diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58b2e299539..90275f8192b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -149,16 +149,11 @@ jobs: run: | cd lightning RUSTFLAGS="--cfg=require_route_graph_test" cargo test - RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown cd .. - name: Run benchmarks on Rust ${{ matrix.toolchain }} run: | cd bench RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench - - name: Run benchmarks with hashbrown on Rust ${{ matrix.toolchain }} - run: | - cd bench - RUSTFLAGS="--cfg=ldk_bench --cfg=require_route_graph_test" cargo bench --features hashbrown check_commits: runs-on: ubuntu-latest @@ -199,15 +194,15 @@ jobs: - name: Run cargo check for release build. run: | cargo check --release - cargo check --no-default-features --features=no-std --release cargo check --no-default-features --features=futures,std --release cargo doc --release - name: Run cargo check for Taproot build. run: | cargo check --release - cargo check --no-default-features --features=no-std --release + cargo check --no-default-features --release cargo check --no-default-features --features=futures,std --release cargo doc --release + cargo doc --no-default-features --release env: RUSTFLAGS: '--cfg=taproot' RUSTDOCFLAGS: '--cfg=taproot' diff --git a/Cargo.toml b/Cargo.toml index ae5d1bc8f0c..add69f35afa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [workspace] resolver = "2" +# When the workspace members change, make sure to update the list here as well +# as in `ci/ci-tests.sh`. members = [ "lightning", "lightning-types", diff --git a/README.md b/README.md index f77910b7a51..a0721e41407 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Crates ----------- 1. [lightning](./lightning) The core of the LDK library, implements the Lightning protocol, channel state machine, - and on-chain logic. Supports `no-std` and exposes only relatively low-level interfaces. + and on-chain logic. Supports `no_std` and exposes only relatively low-level interfaces. 2. [lightning-background-processor](./lightning-background-processor) Utilities to perform required background tasks for Rust Lightning. 3. [lightning-block-sync](./lightning-block-sync) diff --git a/bench/Cargo.toml b/bench/Cargo.toml index 05354890c2a..5bf14377917 100644 --- a/bench/Cargo.toml +++ b/bench/Cargo.toml @@ -8,9 +8,6 @@ edition = "2021" name = "bench" harness = false -[features] -hashbrown = ["lightning/hashbrown"] - [dependencies] lightning = { path = "../lightning", features = ["_test_utils", "criterion"] } lightning-persister = { path = "../lightning-persister", features = ["criterion"] } diff --git a/bench/README.md b/bench/README.md index 7d4cacc9e87..03f6cb6ca0b 100644 --- a/bench/README.md +++ b/bench/README.md @@ -1,6 +1,3 @@ This crate uses criterion to benchmark various LDK functions. It can be run as `RUSTFLAGS=--cfg=ldk_bench cargo bench`. - -For routing or other HashMap-bottlenecked functions, the `hashbrown` feature -should also be benchmarked. diff --git a/ci/check-compiles.sh b/ci/check-compiles.sh index 7ad9f4df196..a067861fb56 100755 --- a/ci/check-compiles.sh +++ b/ci/check-compiles.sh @@ -6,5 +6,5 @@ cargo check cargo doc cargo doc --document-private-items cd fuzz && RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz" cargo check --features=stdin_fuzz -cd ../lightning && cargo check --no-default-features --features=no-std +cd ../lightning && cargo check --no-default-features cd .. && RUSTC_BOOTSTRAP=1 RUSTFLAGS="--cfg=c_bindings" cargo check -Z avoid-dev-deps diff --git a/ci/ci-tests.sh b/ci/ci-tests.sh index aff1a46c49e..47f0621683c 100755 --- a/ci/ci-tests.sh +++ b/ci/ci-tests.sh @@ -11,6 +11,9 @@ function PIN_RELEASE_DEPS { # Starting with version 1.39.0, the `tokio` crate has an MSRV of rustc 1.70.0 [ "$RUSTC_MINOR_VERSION" -lt 70 ] && cargo update -p tokio --precise "1.38.1" --verbose + # Starting with version 0.7.12, the `tokio-util` crate has an MSRV of rustc 1.70.0 + [ "$RUSTC_MINOR_VERSION" -lt 70 ] && cargo update -p tokio-util --precise "0.7.11" --verbose + return 0 # Don't fail the script if our rustc is higher than the last check } @@ -27,11 +30,33 @@ PIN_RELEASE_DEPS # pin the release dependencies in our main workspace export RUST_BACKTRACE=1 -echo -e "\n\nBuilding and testing all workspace crates..." -cargo test --verbose --color always +echo -e "\n\nChecking the full workspace." cargo check --verbose --color always -echo -e "\n\nBuilding and testing Block Sync Clients with features" +# When the workspace members change, make sure to update the list here as well +# as in `Cargo.toml`. +WORKSPACE_MEMBERS=( + lightning + lightning-types + lightning-block-sync + lightning-invoice + lightning-net-tokio + lightning-persister + lightning-background-processor + lightning-rapid-gossip-sync + lightning-custom-message + lightning-transaction-sync + possiblyrandom +) + +echo -e "\n\nChecking, testing, and building docs for all workspace members individually..." +for DIR in "${WORKSPACE_MEMBERS[@]}"; do + cargo test -p "$DIR" --verbose --color always + cargo check -p "$DIR" --verbose --color always + cargo doc -p "$DIR" --document-private-items +done + +echo -e "\n\nChecking and testing Block Sync Clients with features" cargo test -p lightning-block-sync --verbose --color always --features rest-client cargo check -p lightning-block-sync --verbose --color always --features rest-client @@ -77,14 +102,12 @@ grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEAT RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE" done -echo -e "\n\nTesting no-std builds" +echo -e "\n\nTesting no_std builds" for DIR in lightning-invoice lightning-rapid-gossip-sync; do cargo test -p $DIR --verbose --color always --no-default-features done -cargo test -p lightning --verbose --color always --no-default-features --features no-std -# check if there is a conflict between no-std and the default std feature -cargo test -p lightning --verbose --color always --features no-std +cargo test -p lightning --verbose --color always --no-default-features echo -e "\n\nTesting c_bindings builds" # Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively @@ -92,23 +115,23 @@ echo -e "\n\nTesting c_bindings builds" RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always --lib --bins --tests for DIR in lightning-invoice lightning-rapid-gossip-sync; do - # check if there is a conflict between no-std and the c_bindings cfg + # check if there is a conflict between no_std and the c_bindings cfg RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features done # Note that because `$RUSTFLAGS` is not passed through to doctest builds we cannot selectively # disable doctests in `c_bindings` so we skip doctests entirely here. RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning-background-processor --verbose --color always --features futures --no-default-features --lib --bins --tests -RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --features=no-std --lib --bins --tests +RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p lightning --verbose --color always --no-default-features --lib --bins --tests echo -e "\n\nTesting other crate-specific builds" # Note that outbound_commitment_test only runs in this mode because of hardcoded signature values RUSTFLAGS="$RUSTFLAGS --cfg=ldk_test_vectors" cargo test -p lightning --verbose --color always --no-default-features --features=std # This one only works for lightning-invoice -# check that compile with no-std and serde works in lightning-invoice +# check that compile with no_std and serde works in lightning-invoice cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde -echo -e "\n\nTesting no-std build on a downstream no-std crate" +echo -e "\n\nTesting no_std build on a downstream no-std crate" # check no-std compatibility across dependencies pushd no-std-check cargo check --verbose --color always --features lightning-transaction-sync diff --git a/ci/rustfmt.sh b/ci/rustfmt.sh index 1a9053a28dd..973f79ebe5c 100755 --- a/ci/rustfmt.sh +++ b/ci/rustfmt.sh @@ -14,7 +14,7 @@ VERS="" # Run fmt TMP_FILE=$(mktemp) -find . -name '*.rs' -type f |sort >"$TMP_FILE" +git ls-files | grep '.rs$' | sort >"$TMP_FILE" for file in $(comm -23 "$TMP_FILE" rustfmt_excluded_files); do echo "Checking formatting of $file" rustfmt $VERS --edition 2021 --check "$file" diff --git a/contrib/run-rustfmt.sh b/contrib/run-rustfmt.sh index ffce4242f3e..2ef82c5a3e4 100755 --- a/contrib/run-rustfmt.sh +++ b/contrib/run-rustfmt.sh @@ -14,7 +14,7 @@ VERS="" # Run fmt TMP_FILE=$(mktemp) -find . -name '*.rs' -type f |sort >"$TMP_FILE" +git ls-files | grep '.rs$' | sort >"$TMP_FILE" for file in $(comm -23 "$TMP_FILE" rustfmt_excluded_files); do echo "Formatting $file..." rustfmt $VERS --edition 2021 "$file" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 666474f5366..02b808f2383 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -18,7 +18,7 @@ libfuzzer_fuzz = ["libfuzzer-sys"] stdin_fuzz = [] [dependencies] -lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] } +lightning = { path = "../lightning", features = ["regex", "_test_utils"] } lightning-invoice = { path = "../lightning-invoice" } lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" } bech32 = "0.9.1" diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 8929a579c74..ebde87d2ded 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -58,7 +58,9 @@ use lightning::ln::script::ShutdownScript; use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::offers::invoice::UnsignedBolt12Invoice; use lightning::offers::invoice_request::UnsignedInvoiceRequest; -use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath}; +use lightning::onion_message::messenger::{ + BlindedPathType, Destination, MessageRouter, OnionMessagePath, +}; use lightning::routing::router::{InFlightHtlcs, Path, Route, RouteHop, RouteParameters, Router}; use lightning::sign::{ EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider, @@ -141,8 +143,8 @@ impl MessageRouter for FuzzRouter { } fn create_blinded_paths( - &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec, - _secp_ctx: &Secp256k1, + &self, _recipient: PublicKey, _context: MessageContext, _blinded_path: BlindedPathType, + _peers: Vec, _secp_ctx: &Secp256k1, ) -> Result, ()> { unreachable!() } @@ -806,13 +808,13 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { networks: None, remote_network_address: None, }; - $source.peer_connected(&$dest.get_our_node_id(), &init_dest, true).unwrap(); + $source.peer_connected($dest.get_our_node_id(), &init_dest, true).unwrap(); let init_src = Init { features: $source.init_features(), networks: None, remote_network_address: None, }; - $dest.peer_connected(&$source.get_our_node_id(), &init_src, false).unwrap(); + $dest.peer_connected($source.get_our_node_id(), &init_src, false).unwrap(); $source.create_channel($dest.get_our_node_id(), 100_000, 42, 0, None, None).unwrap(); let open_channel = { @@ -825,7 +827,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { } }; - $dest.handle_open_channel(&$source.get_our_node_id(), &open_channel); + $dest.handle_open_channel($source.get_our_node_id(), &open_channel); let accept_channel = { if anchors { let events = $dest.get_and_clear_pending_events(); @@ -860,7 +862,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { } }; - $source.handle_accept_channel(&$dest.get_our_node_id(), &accept_channel); + $source.handle_accept_channel($dest.get_our_node_id(), &accept_channel); let funding_output; { let mut events = $source.get_and_clear_pending_events(); @@ -904,7 +906,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { panic!("Wrong event type"); } }; - $dest.handle_funding_created(&$source.get_our_node_id(), &funding_created); + $dest.handle_funding_created($source.get_our_node_id(), &funding_created); let funding_signed = { let events = $dest.get_and_clear_pending_msg_events(); @@ -923,7 +925,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { panic!("Wrong event type"); } - $source.handle_funding_signed(&$dest.get_our_node_id(), &funding_signed); + $source.handle_funding_signed($dest.get_our_node_id(), &funding_signed); let events = $source.get_and_clear_pending_events(); assert_eq!(events.len(), 1); if let events::Event::ChannelPending { ref counterparty_node_id, .. } = events[0] { @@ -963,7 +965,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { { for node in $nodes.iter() { if node.get_our_node_id() == *node_id { - node.handle_channel_ready(&$nodes[idx].get_our_node_id(), msg); + node.handle_channel_ready($nodes[idx].get_our_node_id(), msg); } } } else { @@ -1134,7 +1136,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { for update_add in update_add_htlcs.iter() { out.locked_write(format!("Delivering update_add_htlc to node {}.\n", idx).as_bytes()); if !$corrupt_forward { - dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), update_add); + dest.handle_update_add_htlc(nodes[$node].get_our_node_id(), update_add); } else { // Corrupt the update_add_htlc message so that its HMAC // check will fail and we generate a @@ -1143,24 +1145,24 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { let mut msg_ser = update_add.encode(); msg_ser[1000] ^= 0xff; let new_msg = UpdateAddHTLC::read(&mut Cursor::new(&msg_ser)).unwrap(); - dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), &new_msg); + dest.handle_update_add_htlc(nodes[$node].get_our_node_id(), &new_msg); } } for update_fulfill in update_fulfill_htlcs.iter() { out.locked_write(format!("Delivering update_fulfill_htlc to node {}.\n", idx).as_bytes()); - dest.handle_update_fulfill_htlc(&nodes[$node].get_our_node_id(), update_fulfill); + dest.handle_update_fulfill_htlc(nodes[$node].get_our_node_id(), update_fulfill); } for update_fail in update_fail_htlcs.iter() { out.locked_write(format!("Delivering update_fail_htlc to node {}.\n", idx).as_bytes()); - dest.handle_update_fail_htlc(&nodes[$node].get_our_node_id(), update_fail); + dest.handle_update_fail_htlc(nodes[$node].get_our_node_id(), update_fail); } for update_fail_malformed in update_fail_malformed_htlcs.iter() { out.locked_write(format!("Delivering update_fail_malformed_htlc to node {}.\n", idx).as_bytes()); - dest.handle_update_fail_malformed_htlc(&nodes[$node].get_our_node_id(), update_fail_malformed); + dest.handle_update_fail_malformed_htlc(nodes[$node].get_our_node_id(), update_fail_malformed); } if let Some(msg) = update_fee { out.locked_write(format!("Delivering update_fee to node {}.\n", idx).as_bytes()); - dest.handle_update_fee(&nodes[$node].get_our_node_id(), &msg); + dest.handle_update_fee(nodes[$node].get_our_node_id(), &msg); } let processed_change = !update_add_htlcs.is_empty() || !update_fulfill_htlcs.is_empty() || !update_fail_htlcs.is_empty() || !update_fail_malformed_htlcs.is_empty(); @@ -1177,7 +1179,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { break; } out.locked_write(format!("Delivering commitment_signed to node {}.\n", idx).as_bytes()); - dest.handle_commitment_signed(&nodes[$node].get_our_node_id(), &commitment_signed); + dest.handle_commitment_signed(nodes[$node].get_our_node_id(), &commitment_signed); break; } } @@ -1186,7 +1188,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { for (idx, dest) in nodes.iter().enumerate() { if dest.get_our_node_id() == *node_id { out.locked_write(format!("Delivering revoke_and_ack to node {}.\n", idx).as_bytes()); - dest.handle_revoke_and_ack(&nodes[$node].get_our_node_id(), msg); + dest.handle_revoke_and_ack(nodes[$node].get_our_node_id(), msg); } } }, @@ -1194,7 +1196,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { for (idx, dest) in nodes.iter().enumerate() { if dest.get_our_node_id() == *node_id { out.locked_write(format!("Delivering channel_reestablish to node {}.\n", idx).as_bytes()); - dest.handle_channel_reestablish(&nodes[$node].get_our_node_id(), msg); + dest.handle_channel_reestablish(nodes[$node].get_our_node_id(), msg); } } }, @@ -1453,16 +1455,16 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { 0x0c => { if !chan_a_disconnected { - nodes[0].peer_disconnected(&nodes[1].get_our_node_id()); - nodes[1].peer_disconnected(&nodes[0].get_our_node_id()); + nodes[0].peer_disconnected(nodes[1].get_our_node_id()); + nodes[1].peer_disconnected(nodes[0].get_our_node_id()); chan_a_disconnected = true; drain_msg_events_on_disconnect!(0); } }, 0x0d => { if !chan_b_disconnected { - nodes[1].peer_disconnected(&nodes[2].get_our_node_id()); - nodes[2].peer_disconnected(&nodes[1].get_our_node_id()); + nodes[1].peer_disconnected(nodes[2].get_our_node_id()); + nodes[2].peer_disconnected(nodes[1].get_our_node_id()); chan_b_disconnected = true; drain_msg_events_on_disconnect!(2); } @@ -1474,13 +1476,13 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { networks: None, remote_network_address: None, }; - nodes[0].peer_connected(&nodes[1].get_our_node_id(), &init_1, true).unwrap(); + nodes[0].peer_connected(nodes[1].get_our_node_id(), &init_1, true).unwrap(); let init_0 = Init { features: nodes[0].init_features(), networks: None, remote_network_address: None, }; - nodes[1].peer_connected(&nodes[0].get_our_node_id(), &init_0, false).unwrap(); + nodes[1].peer_connected(nodes[0].get_our_node_id(), &init_0, false).unwrap(); chan_a_disconnected = false; } }, @@ -1491,13 +1493,13 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { networks: None, remote_network_address: None, }; - nodes[1].peer_connected(&nodes[2].get_our_node_id(), &init_2, true).unwrap(); + nodes[1].peer_connected(nodes[2].get_our_node_id(), &init_2, true).unwrap(); let init_1 = Init { features: nodes[1].init_features(), networks: None, remote_network_address: None, }; - nodes[2].peer_connected(&nodes[1].get_our_node_id(), &init_1, false).unwrap(); + nodes[2].peer_connected(nodes[1].get_our_node_id(), &init_1, false).unwrap(); chan_b_disconnected = false; } }, @@ -1534,7 +1536,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { 0x2c => { if !chan_a_disconnected { - nodes[1].peer_disconnected(&nodes[0].get_our_node_id()); + nodes[1].peer_disconnected(nodes[0].get_our_node_id()); chan_a_disconnected = true; push_excess_b_events!( nodes[1].get_and_clear_pending_msg_events().drain(..), @@ -1550,14 +1552,14 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { }, 0x2d => { if !chan_a_disconnected { - nodes[0].peer_disconnected(&nodes[1].get_our_node_id()); + nodes[0].peer_disconnected(nodes[1].get_our_node_id()); chan_a_disconnected = true; nodes[0].get_and_clear_pending_msg_events(); ab_events.clear(); ba_events.clear(); } if !chan_b_disconnected { - nodes[2].peer_disconnected(&nodes[1].get_our_node_id()); + nodes[2].peer_disconnected(nodes[1].get_our_node_id()); chan_b_disconnected = true; nodes[2].get_and_clear_pending_msg_events(); bc_events.clear(); @@ -1570,7 +1572,7 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { }, 0x2e => { if !chan_b_disconnected { - nodes[1].peer_disconnected(&nodes[2].get_our_node_id()); + nodes[1].peer_disconnected(nodes[2].get_our_node_id()); chan_b_disconnected = true; push_excess_b_events!( nodes[1].get_and_clear_pending_msg_events().drain(..), @@ -1759,13 +1761,13 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { networks: None, remote_network_address: None, }; - nodes[0].peer_connected(&nodes[1].get_our_node_id(), &init_1, true).unwrap(); + nodes[0].peer_connected(nodes[1].get_our_node_id(), &init_1, true).unwrap(); let init_0 = Init { features: nodes[0].init_features(), networks: None, remote_network_address: None, }; - nodes[1].peer_connected(&nodes[0].get_our_node_id(), &init_0, false).unwrap(); + nodes[1].peer_connected(nodes[0].get_our_node_id(), &init_0, false).unwrap(); chan_a_disconnected = false; } if chan_b_disconnected { @@ -1774,13 +1776,13 @@ pub fn do_test(data: &[u8], underlying_out: Out, anchors: bool) { networks: None, remote_network_address: None, }; - nodes[1].peer_connected(&nodes[2].get_our_node_id(), &init_2, true).unwrap(); + nodes[1].peer_connected(nodes[2].get_our_node_id(), &init_2, true).unwrap(); let init_1 = Init { features: nodes[1].init_features(), networks: None, remote_network_address: None, }; - nodes[2].peer_connected(&nodes[1].get_our_node_id(), &init_1, false).unwrap(); + nodes[2].peer_connected(nodes[1].get_our_node_id(), &init_1, false).unwrap(); chan_b_disconnected = false; } diff --git a/fuzz/src/full_stack.rs b/fuzz/src/full_stack.rs index 90449248e32..4d1f2a7fbc1 100644 --- a/fuzz/src/full_stack.rs +++ b/fuzz/src/full_stack.rs @@ -51,7 +51,9 @@ use lightning::ln::script::ShutdownScript; use lightning::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret}; use lightning::offers::invoice::UnsignedBolt12Invoice; use lightning::offers::invoice_request::UnsignedInvoiceRequest; -use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath}; +use lightning::onion_message::messenger::{ + BlindedPathType, Destination, MessageRouter, OnionMessagePath, +}; use lightning::routing::gossip::{NetworkGraph, P2PGossipSync}; use lightning::routing::router::{ InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router, @@ -176,8 +178,8 @@ impl MessageRouter for FuzzRouter { } fn create_blinded_paths( - &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec, - _secp_ctx: &Secp256k1, + &self, _recipient: PublicKey, _context: MessageContext, _blinded_path: BlindedPathType, + _peers: Vec, _secp_ctx: &Secp256k1, ) -> Result, ()> { unreachable!() } diff --git a/fuzz/src/invoice_request_deser.rs b/fuzz/src/invoice_request_deser.rs index f93199cf94c..fb5122ec23d 100644 --- a/fuzz/src/invoice_request_deser.rs +++ b/fuzz/src/invoice_request_deser.rs @@ -85,7 +85,7 @@ fn build_response( let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: OfferId([42; 32]), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: invoice_request.quantity(), payer_note_truncated: invoice_request .payer_note() diff --git a/fuzz/src/onion_message.rs b/fuzz/src/onion_message.rs index 33458436c66..8f9c384f1ff 100644 --- a/fuzz/src/onion_message.rs +++ b/fuzz/src/onion_message.rs @@ -5,7 +5,9 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature; use bitcoin::secp256k1::schnorr; use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey}; -use lightning::blinded_path::message::{BlindedMessagePath, MessageContext, OffersContext}; +use lightning::blinded_path::message::{ + AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext, +}; use lightning::blinded_path::EmptyNodeIdLookUp; use lightning::ln::features::InitFeatures; use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler}; @@ -16,8 +18,8 @@ use lightning::onion_message::async_payments::{ AsyncPaymentsMessageHandler, HeldHtlcAvailable, ReleaseHeldHtlc, }; use lightning::onion_message::messenger::{ - CustomOnionMessageHandler, Destination, MessageRouter, MessageSendInstructions, - OnionMessagePath, OnionMessenger, Responder, ResponseInstruction, + BlindedPathType, CustomOnionMessageHandler, Destination, MessageRouter, + MessageSendInstructions, OnionMessagePath, OnionMessenger, Responder, ResponseInstruction, }; use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler}; use lightning::onion_message::packet::OnionMessageContents; @@ -68,8 +70,8 @@ pub fn do_test(data: &[u8], logger: &L) { features.set_onion_messages_optional(); let init = msgs::Init { features, networks: None, remote_network_address: None }; - onion_messenger.peer_connected(&peer_node_id, &init, false).unwrap(); - onion_messenger.handle_onion_message(&peer_node_id, &msg); + onion_messenger.peer_connected(peer_node_id, &init, false).unwrap(); + onion_messenger.handle_onion_message(peer_node_id, &msg); } } @@ -96,8 +98,8 @@ impl MessageRouter for TestMessageRouter { } fn create_blinded_paths( - &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec, - _secp_ctx: &Secp256k1, + &self, _recipient: PublicKey, _context: MessageContext, _blinded_path: BlindedPathType, + _peers: Vec, _secp_ctx: &Secp256k1, ) -> Result, ()> { unreachable!() } @@ -124,12 +126,9 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler { Some(resp) => resp, None => return None, }; - Some(( - ReleaseHeldHtlc { payment_release_secret: message.payment_release_secret }, - responder.respond(), - )) + Some((ReleaseHeldHtlc {}, responder.respond())) } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } #[derive(Debug)] diff --git a/fuzz/src/router.rs b/fuzz/src/router.rs index 41e8162575a..df97cbb978a 100644 --- a/fuzz/src/router.rs +++ b/fuzz/src/router.rs @@ -242,7 +242,6 @@ pub fn do_test(data: &[u8], out: Out) { is_channel_ready: true, is_usable: true, is_announced: true, - balance_msat: 0, outbound_capacity_msat: capacity.saturating_mul(1000), next_outbound_htlc_limit_msat: capacity.saturating_mul(1000), next_outbound_htlc_minimum_msat: 0, diff --git a/lightning-background-processor/Cargo.toml b/lightning-background-processor/Cargo.toml index 70c19c5c76d..0afc18fdfbb 100644 --- a/lightning-background-processor/Cargo.toml +++ b/lightning-background-processor/Cargo.toml @@ -15,12 +15,14 @@ rustdoc-args = ["--cfg", "docsrs"] [features] futures = [ ] -std = [] +std = ["lightning/std", "bitcoin-io/std", "bitcoin_hashes/std"] default = ["std"] [dependencies] bitcoin = { version = "0.32.2", default-features = false } +bitcoin_hashes = { version = "0.14.0", default-features = false } +bitcoin-io = { version = "0.1.2", default-features = false } lightning = { version = "0.0.124", path = "../lightning", default-features = false } lightning-rapid-gossip-sync = { version = "0.0.124", path = "../lightning-rapid-gossip-sync", default-features = false } diff --git a/lightning-background-processor/src/lib.rs b/lightning-background-processor/src/lib.rs index bbe1545d044..59b68dbfb33 100644 --- a/lightning-background-processor/src/lib.rs +++ b/lightning-background-processor/src/lib.rs @@ -1,7 +1,6 @@ //! Utilities that take care of tasks that (1) need to happen periodically to keep Rust-Lightning -//! running properly, and (2) either can or should be run in the background. See docs for -//! [`BackgroundProcessor`] for more details on the nitty-gritty. - +//! running properly, and (2) either can or should be run in the background. +#![cfg_attr(feature = "std", doc = "See docs for [`BackgroundProcessor`] for more details.")] #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] #![deny(missing_docs)] @@ -325,9 +324,17 @@ macro_rules! define_run_body { let mut have_decayed_scorer = false; loop { + log_trace!($logger, "Processing ChannelManager events..."); $process_channel_manager_events; + log_trace!($logger, "Done processing ChannelManager events."); + + log_trace!($logger, "Processing ChainMonitor events..."); $process_chain_monitor_events; + log_trace!($logger, "Done processing ChainMonitor events."); + + log_trace!($logger, "Processing OnionMessageHandler events..."); $process_onion_message_handler_events; + log_trace!($logger, "Done processing OnionMessageHandler events."); // Note that the PeerManager::process_events may block on ChannelManager's locks, // hence it comes last here. When the ChannelManager finishes whatever it's doing, @@ -340,7 +347,9 @@ macro_rules! define_run_body { // ChannelManager, we want to minimize methods blocking on a ChannelManager // generally, and as a fallback place such blocking only immediately before // persistence. + log_trace!($logger, "Processing PeerManager events..."); $peer_manager.as_ref().process_events(); + log_trace!($logger, "Done processing PeerManager events."); // Exit the loop if the background processor was requested to stop. if $loop_exit_check { @@ -1648,7 +1657,7 @@ mod tests { }; nodes[i] .node - .peer_connected(&nodes[j].node.get_our_node_id(), &init_i, true) + .peer_connected(nodes[j].node.get_our_node_id(), &init_i, true) .unwrap(); let init_j = Init { features: nodes[i].node.init_features(), @@ -1657,7 +1666,7 @@ mod tests { }; nodes[j] .node - .peer_connected(&nodes[i].node.get_our_node_id(), &init_j, false) + .peer_connected(nodes[i].node.get_our_node_id(), &init_j, false) .unwrap(); } } @@ -1685,14 +1694,14 @@ mod tests { MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id() ); - $node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &msg_a); + $node_b.node.handle_funding_created($node_a.node.get_our_node_id(), &msg_a); get_event!($node_b, Event::ChannelPending); let msg_b = get_event_msg!( $node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id() ); - $node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &msg_b); + $node_a.node.handle_funding_signed($node_b.node.get_our_node_id(), &msg_b); get_event!($node_a, Event::ChannelPending); tx }}; @@ -1709,13 +1718,13 @@ mod tests { MessageSendEvent::SendOpenChannel, $node_b.node.get_our_node_id() ); - $node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), &msg_a); + $node_b.node.handle_open_channel($node_a.node.get_our_node_id(), &msg_a); let msg_b = get_event_msg!( $node_b, MessageSendEvent::SendAcceptChannel, $node_a.node.get_our_node_id() ); - $node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), &msg_b); + $node_a.node.handle_accept_channel($node_b.node.get_our_node_id(), &msg_b); }}; } @@ -2115,10 +2124,10 @@ mod tests { .funding_transaction_generated(temporary_channel_id, node_1_id, funding_tx.clone()) .unwrap(); let msg_0 = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, node_1_id); - nodes[1].node.handle_funding_created(&node_0_id, &msg_0); + nodes[1].node.handle_funding_created(node_0_id, &msg_0); get_event!(nodes[1], Event::ChannelPending); let msg_1 = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, node_0_id); - nodes[0].node.handle_funding_signed(&node_1_id, &msg_1); + nodes[0].node.handle_funding_signed(node_1_id, &msg_1); let _ = channel_pending_recv .recv_timeout(Duration::from_secs(EVENT_DEADLINE)) .expect("ChannelPending not handled within deadline"); @@ -2128,10 +2137,10 @@ mod tests { let as_funding = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, node_1_id); confirm_transaction(&mut nodes[1], &funding_tx); let bs_funding = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, node_0_id); - nodes[0].node.handle_channel_ready(&node_1_id, &bs_funding); + nodes[0].node.handle_channel_ready(node_1_id, &bs_funding); let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, node_1_id); - nodes[1].node.handle_channel_ready(&node_0_id, &as_funding); + nodes[1].node.handle_channel_ready(node_0_id, &as_funding); let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id); let broadcast_funding = diff --git a/lightning-custom-message/src/lib.rs b/lightning-custom-message/src/lib.rs index a0948f23b5f..c9758986d43 100644 --- a/lightning-custom-message/src/lib.rs +++ b/lightning-custom-message/src/lib.rs @@ -61,23 +61,23 @@ //! impl CustomMessageHandler for FooHandler { //! // ... //! # fn handle_custom_message( -//! # &self, _msg: Self::CustomMessage, _sender_node_id: &PublicKey +//! # &self, _msg: Self::CustomMessage, _sender_node_id: PublicKey //! # ) -> Result<(), LightningError> { //! # unimplemented!() //! # } //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } -//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # fn peer_disconnected(&self, _their_node_id: PublicKey) { //! # unimplemented!() //! # } -//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # fn peer_connected(&self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { //! # unimplemented!() //! # } //! # fn provided_node_features(&self) -> NodeFeatures { //! # unimplemented!() //! # } -//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { //! # unimplemented!() //! # } //! } @@ -113,23 +113,23 @@ //! impl CustomMessageHandler for BarHandler { //! // ... //! # fn handle_custom_message( -//! # &self, _msg: Self::CustomMessage, _sender_node_id: &PublicKey +//! # &self, _msg: Self::CustomMessage, _sender_node_id: PublicKey //! # ) -> Result<(), LightningError> { //! # unimplemented!() //! # } //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } -//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # fn peer_disconnected(&self, _their_node_id: PublicKey) { //! # unimplemented!() //! # } -//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # fn peer_connected(&self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { //! # unimplemented!() //! # } //! # fn provided_node_features(&self) -> NodeFeatures { //! # unimplemented!() //! # } -//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { //! # unimplemented!() //! # } //! } @@ -165,23 +165,23 @@ //! impl CustomMessageHandler for BazHandler { //! // ... //! # fn handle_custom_message( -//! # &self, _msg: Self::CustomMessage, _sender_node_id: &PublicKey +//! # &self, _msg: Self::CustomMessage, _sender_node_id: PublicKey //! # ) -> Result<(), LightningError> { //! # unimplemented!() //! # } //! # fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { //! # unimplemented!() //! # } -//! # fn peer_disconnected(&self, _their_node_id: &PublicKey) { +//! # fn peer_disconnected(&self, _their_node_id: PublicKey) { //! # unimplemented!() //! # } -//! # fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { +//! # fn peer_connected(&self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { //! # unimplemented!() //! # } //! # fn provided_node_features(&self) -> NodeFeatures { //! # unimplemented!() //! # } -//! # fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { +//! # fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { //! # unimplemented!() //! # } //! } @@ -279,7 +279,7 @@ macro_rules! composite_custom_message_handler { impl $crate::lightning::ln::peer_handler::CustomMessageHandler for $handler { fn handle_custom_message( - &self, msg: Self::CustomMessage, sender_node_id: &$crate::bitcoin::secp256k1::PublicKey + &self, msg: Self::CustomMessage, sender_node_id: $crate::bitcoin::secp256k1::PublicKey ) -> Result<(), $crate::lightning::ln::msgs::LightningError> { match msg { $( @@ -305,13 +305,13 @@ macro_rules! composite_custom_message_handler { .collect() } - fn peer_disconnected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey) { + fn peer_disconnected(&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey) { $( self.$field.peer_disconnected(their_node_id); )* } - fn peer_connected(&self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey, msg: &$crate::lightning::ln::msgs::Init, inbound: bool) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: $crate::bitcoin::secp256k1::PublicKey, msg: &$crate::lightning::ln::msgs::Init, inbound: bool) -> Result<(), ()> { let mut result = Ok(()); $( if let Err(e) = self.$field.peer_connected(their_node_id, msg, inbound) { @@ -329,7 +329,7 @@ macro_rules! composite_custom_message_handler { } fn provided_init_features( - &self, their_node_id: &$crate::bitcoin::secp256k1::PublicKey + &self, their_node_id: $crate::bitcoin::secp256k1::PublicKey ) -> $crate::lightning::ln::features::InitFeatures { $crate::lightning::ln::features::InitFeatures::empty() $( diff --git a/lightning-net-tokio/src/lib.rs b/lightning-net-tokio/src/lib.rs index a5f4de470df..89ac7a52ec2 100644 --- a/lightning-net-tokio/src/lib.rs +++ b/lightning-net-tokio/src/lib.rs @@ -660,16 +660,18 @@ mod tests { } impl RoutingMessageHandler for MsgHandler { fn handle_node_announcement( - &self, _msg: &NodeAnnouncement, + &self, _their_node_id: Option, _msg: &NodeAnnouncement, ) -> Result { Ok(false) } fn handle_channel_announcement( - &self, _msg: &ChannelAnnouncement, + &self, _their_node_id: Option, _msg: &ChannelAnnouncement, ) -> Result { Ok(false) } - fn handle_channel_update(&self, _msg: &ChannelUpdate) -> Result { + fn handle_channel_update( + &self, _their_node_id: Option, _msg: &ChannelUpdate, + ) -> Result { Ok(false) } fn get_next_channel_announcement( @@ -683,34 +685,34 @@ mod tests { None } fn peer_connected( - &self, _their_node_id: &PublicKey, _init_msg: &Init, _inbound: bool, + &self, _their_node_id: PublicKey, _init_msg: &Init, _inbound: bool, ) -> Result<(), ()> { Ok(()) } fn handle_reply_channel_range( - &self, _their_node_id: &PublicKey, _msg: ReplyChannelRange, + &self, _their_node_id: PublicKey, _msg: ReplyChannelRange, ) -> Result<(), LightningError> { Ok(()) } fn handle_reply_short_channel_ids_end( - &self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd, + &self, _their_node_id: PublicKey, _msg: ReplyShortChannelIdsEnd, ) -> Result<(), LightningError> { Ok(()) } fn handle_query_channel_range( - &self, _their_node_id: &PublicKey, _msg: QueryChannelRange, + &self, _their_node_id: PublicKey, _msg: QueryChannelRange, ) -> Result<(), LightningError> { Ok(()) } fn handle_query_short_channel_ids( - &self, _their_node_id: &PublicKey, _msg: QueryShortChannelIds, + &self, _their_node_id: PublicKey, _msg: QueryShortChannelIds, ) -> Result<(), LightningError> { Ok(()) } fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { InitFeatures::empty() } fn processing_queue_high(&self) -> bool { @@ -718,75 +720,73 @@ mod tests { } } impl ChannelMessageHandler for MsgHandler { - fn handle_open_channel(&self, _their_node_id: &PublicKey, _msg: &OpenChannel) {} - fn handle_accept_channel(&self, _their_node_id: &PublicKey, _msg: &AcceptChannel) {} - fn handle_funding_created(&self, _their_node_id: &PublicKey, _msg: &FundingCreated) {} - fn handle_funding_signed(&self, _their_node_id: &PublicKey, _msg: &FundingSigned) {} - fn handle_channel_ready(&self, _their_node_id: &PublicKey, _msg: &ChannelReady) {} - fn handle_shutdown(&self, _their_node_id: &PublicKey, _msg: &Shutdown) {} - fn handle_closing_signed(&self, _their_node_id: &PublicKey, _msg: &ClosingSigned) {} - fn handle_update_add_htlc(&self, _their_node_id: &PublicKey, _msg: &UpdateAddHTLC) {} - fn handle_update_fulfill_htlc(&self, _their_node_id: &PublicKey, _msg: &UpdateFulfillHTLC) { - } - fn handle_update_fail_htlc(&self, _their_node_id: &PublicKey, _msg: &UpdateFailHTLC) {} + fn handle_open_channel(&self, _their_node_id: PublicKey, _msg: &OpenChannel) {} + fn handle_accept_channel(&self, _their_node_id: PublicKey, _msg: &AcceptChannel) {} + fn handle_funding_created(&self, _their_node_id: PublicKey, _msg: &FundingCreated) {} + fn handle_funding_signed(&self, _their_node_id: PublicKey, _msg: &FundingSigned) {} + fn handle_channel_ready(&self, _their_node_id: PublicKey, _msg: &ChannelReady) {} + fn handle_shutdown(&self, _their_node_id: PublicKey, _msg: &Shutdown) {} + fn handle_closing_signed(&self, _their_node_id: PublicKey, _msg: &ClosingSigned) {} + fn handle_update_add_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateAddHTLC) {} + fn handle_update_fulfill_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateFulfillHTLC) {} + fn handle_update_fail_htlc(&self, _their_node_id: PublicKey, _msg: &UpdateFailHTLC) {} fn handle_update_fail_malformed_htlc( - &self, _their_node_id: &PublicKey, _msg: &UpdateFailMalformedHTLC, + &self, _their_node_id: PublicKey, _msg: &UpdateFailMalformedHTLC, ) { } - fn handle_commitment_signed(&self, _their_node_id: &PublicKey, _msg: &CommitmentSigned) {} - fn handle_revoke_and_ack(&self, _their_node_id: &PublicKey, _msg: &RevokeAndACK) {} - fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {} + fn handle_commitment_signed(&self, _their_node_id: PublicKey, _msg: &CommitmentSigned) {} + fn handle_revoke_and_ack(&self, _their_node_id: PublicKey, _msg: &RevokeAndACK) {} + fn handle_update_fee(&self, _their_node_id: PublicKey, _msg: &UpdateFee) {} fn handle_announcement_signatures( - &self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures, + &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_stfu(&self, _their_node_id: &PublicKey, _msg: &Stfu) {} + 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_stfu(&self, _their_node_id: PublicKey, _msg: &Stfu) {} #[cfg(splicing)] - fn handle_splice_init(&self, _their_node_id: &PublicKey, _msg: &SpliceInit) {} + fn handle_splice_init(&self, _their_node_id: PublicKey, _msg: &SpliceInit) {} #[cfg(splicing)] - fn handle_splice_ack(&self, _their_node_id: &PublicKey, _msg: &SpliceAck) {} + fn handle_splice_ack(&self, _their_node_id: PublicKey, _msg: &SpliceAck) {} #[cfg(splicing)] - fn handle_splice_locked(&self, _their_node_id: &PublicKey, _msg: &SpliceLocked) {} - 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 { + fn handle_splice_locked(&self, _their_node_id: PublicKey, _msg: &SpliceLocked) {} + 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); self.pubkey_disconnected.clone().try_send(()).unwrap(); } } fn peer_connected( - &self, their_node_id: &PublicKey, _init_msg: &Init, _inbound: bool, + &self, their_node_id: PublicKey, _init_msg: &Init, _inbound: bool, ) -> Result<(), ()> { - if *their_node_id == self.expected_pubkey { + if their_node_id == self.expected_pubkey { self.pubkey_connected.clone().try_send(()).unwrap(); } Ok(()) } - fn handle_channel_reestablish( - &self, _their_node_id: &PublicKey, _msg: &ChannelReestablish, - ) { + fn handle_channel_reestablish(&self, _their_node_id: PublicKey, _msg: &ChannelReestablish) { } - fn handle_error(&self, _their_node_id: &PublicKey, _msg: &ErrorMessage) {} + fn handle_error(&self, _their_node_id: PublicKey, _msg: &ErrorMessage) {} fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { InitFeatures::empty() } fn get_chain_hashes(&self) -> Option> { Some(vec![ChainHash::using_genesis_block(Network::Testnet)]) } + fn message_received(&self) {} } impl MessageSendEventsProvider for MsgHandler { fn get_and_clear_pending_msg_events(&self) -> Vec { diff --git a/lightning-rapid-gossip-sync/Cargo.toml b/lightning-rapid-gossip-sync/Cargo.toml index ef28f294378..03efbde3daa 100644 --- a/lightning-rapid-gossip-sync/Cargo.toml +++ b/lightning-rapid-gossip-sync/Cargo.toml @@ -11,11 +11,13 @@ Utility to process gossip routing data from Rapid Gossip Sync Server. [features] default = ["std"] -std = [] +std = ["bitcoin-io/std", "bitcoin_hashes/std"] [dependencies] lightning = { version = "0.0.124", path = "../lightning", default-features = false } bitcoin = { version = "0.32.2", default-features = false } +bitcoin_hashes = { version = "0.14.0", default-features = false } +bitcoin-io = { version = "0.1.2", default-features = false } [target.'cfg(ldk_bench)'.dependencies] criterion = { version = "0.4", optional = true, default-features = false } diff --git a/lightning-rapid-gossip-sync/src/lib.rs b/lightning-rapid-gossip-sync/src/lib.rs index 2bae65cb8e8..429a3560be0 100644 --- a/lightning-rapid-gossip-sync/src/lib.rs +++ b/lightning-rapid-gossip-sync/src/lib.rs @@ -35,8 +35,15 @@ //! Note that the first ever rapid sync should use `0` for `last_sync_timestamp`. //! //! After the gossip data snapshot has been downloaded, one of the client's graph processing -//! functions needs to be called. In this example, we process the update by reading its contents -//! from disk, which we do by calling [`RapidGossipSync::update_network_graph`]: +//! functions needs to be called. +#![cfg_attr( + feature = "std", + doc = "In this example, we process the update by reading its contents from disk, which we do by calling [`RapidGossipSync::update_network_graph`]:" +)] +#![cfg_attr( + not(feature = "std"), + doc = "In this example, we process the update by reading its contents from disk, which we do by calling [`RapidGossipSync::update_network_graph_no_std`]:" +)] //! //! ``` //! use bitcoin::constants::genesis_block; @@ -54,10 +61,17 @@ //! let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); //! let rapid_sync = RapidGossipSync::new(&network_graph, &logger); //! let snapshot_contents: &[u8] = &[0; 0]; -//! // In no-std you need to provide the current time in unix epoch seconds -//! // otherwise you can use update_network_graph -//! let current_time_unix = 0; -//! let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix)); +//! // In non-`std` environments you need to provide the current time in unix epoch seconds +//! // otherwise you can use `update_network_graph`: +#![cfg_attr( + feature = "std", + doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph(snapshot_contents);" +)] +#![cfg_attr(not(feature = "std"), doc = "let current_time_unix = 0;")] +#![cfg_attr( + not(feature = "std"), + doc = "let new_last_sync_timestamp_result = rapid_sync.update_network_graph_no_std(snapshot_contents, Some(current_time_unix));" +)] //! ``` #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] diff --git a/lightning-transaction-sync/Cargo.toml b/lightning-transaction-sync/Cargo.toml index bca6e0a7c04..34105ea3e90 100644 --- a/lightning-transaction-sync/Cargo.toml +++ b/lightning-transaction-sync/Cargo.toml @@ -32,7 +32,7 @@ electrum-client = { version = "0.21.0", optional = true } [dev-dependencies] lightning = { version = "0.0.124", path = "../lightning", default-features = false, features = ["std", "_test_utils"] } -tokio = { version = "1.35.0", features = ["full"] } +tokio = { version = "1.35.0", features = ["macros"] } [target.'cfg(not(target_os = "windows"))'.dev-dependencies] electrsd = { version = "0.28.0", default-features = false, features = ["legacy"] } diff --git a/lightning-transaction-sync/src/common.rs b/lightning-transaction-sync/src/common.rs index 1d6e64bab00..88e52de186d 100644 --- a/lightning-transaction-sync/src/common.rs +++ b/lightning-transaction-sync/src/common.rs @@ -1,3 +1,10 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + use bitcoin::block::Header; use bitcoin::{BlockHash, OutPoint, Transaction, Txid}; use lightning::chain::channelmonitor::ANTI_REORG_DELAY; diff --git a/lightning-transaction-sync/src/electrum.rs b/lightning-transaction-sync/src/electrum.rs index 015cb42c639..78fca1b168f 100644 --- a/lightning-transaction-sync/src/electrum.rs +++ b/lightning-transaction-sync/src/electrum.rs @@ -1,3 +1,10 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + use crate::common::{ConfirmedTx, FilterQueue, SyncState}; use crate::error::{InternalError, TxSyncError}; diff --git a/lightning-transaction-sync/src/error.rs b/lightning-transaction-sync/src/error.rs index be59cb026b4..57068b151d2 100644 --- a/lightning-transaction-sync/src/error.rs +++ b/lightning-transaction-sync/src/error.rs @@ -1,3 +1,10 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + use std::fmt; #[derive(Debug)] diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs index 564d7f1773a..8b8b39cfb4f 100644 --- a/lightning-transaction-sync/src/esplora.rs +++ b/lightning-transaction-sync/src/esplora.rs @@ -1,3 +1,10 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + use crate::common::{ConfirmedTx, FilterQueue, SyncState}; use crate::error::{InternalError, TxSyncError}; diff --git a/lightning-transaction-sync/src/lib.rs b/lightning-transaction-sync/src/lib.rs index 96e0c0dfe9c..9c6831cef5d 100644 --- a/lightning-transaction-sync/src/lib.rs +++ b/lightning-transaction-sync/src/lib.rs @@ -1,3 +1,10 @@ +// This file is Copyright its original authors, visible in version control history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license , at your option. You may not use this file except in +// accordance with one or both of these licenses. + //! Provides utilities for syncing LDK via the transaction-based [`Confirm`] interface. //! //! The provided synchronization clients need to be registered with a [`ChainMonitor`] via the diff --git a/lightning-types/Cargo.toml b/lightning-types/Cargo.toml index 9e8feedf6ef..f3eeec0f1a9 100644 --- a/lightning-types/Cargo.toml +++ b/lightning-types/Cargo.toml @@ -17,8 +17,6 @@ _test_utils = [] [dependencies] bitcoin = { version = "0.32.2", default-features = false } -# TODO: Once we switch to bitcoin 0.32 drop this explicit dep: -hex-conservative = { version = "0.2", default-features = false } bech32 = { version = "0.9", default-features = false } [lints] diff --git a/lightning-types/src/payment.rs b/lightning-types/src/payment.rs index 6b8854ac5f8..a2832c6b559 100644 --- a/lightning-types/src/payment.rs +++ b/lightning-types/src/payment.rs @@ -14,9 +14,7 @@ use alloc::vec::Vec; use core::borrow::Borrow; use bitcoin::hashes::{sha256::Hash as Sha256, Hash as _}; - -// TODO: Once we switch to rust-bitcoin 0.32, import this as bitcoin::hex -use hex_conservative::display::impl_fmt_traits; +use bitcoin::hex::display::impl_fmt_traits; /// The payment hash is the hash of the [`PaymentPreimage`] which is the value used to lock funds /// in HTLCs while they transit the lightning network. diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index 8fa85f7a2fb..3a1939733a6 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -29,7 +29,6 @@ max_level_trace = [] # This is unsafe to use in production because it may result in the counterparty publishing taking our funds. unsafe_revoked_tx_signing = [] -no-std = ["hashbrown", "possiblyrandom", "libm"] std = [] # Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases @@ -44,12 +43,12 @@ lightning-invoice = { version = "0.32.0", path = "../lightning-invoice", default bech32 = { version = "0.9.1", default-features = false } bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] } -hashbrown = { version = "0.13", optional = true, default-features = false } -possiblyrandom = { version = "0.2", path = "../possiblyrandom", optional = true, default-features = false } +hashbrown = { version = "0.13", default-features = false } +possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false } regex = { version = "1.5.6", optional = true } backtrace = { version = "0.3", optional = true } -libm = { version = "0.2", optional = true, default-features = false } +libm = { version = "0.2", default-features = false } [dev-dependencies] regex = "1.5.6" diff --git a/lightning/src/blinded_path/message.rs b/lightning/src/blinded_path/message.rs index e3899b50edb..805d35a010c 100644 --- a/lightning/src/blinded_path/message.rs +++ b/lightning/src/blinded_path/message.rs @@ -280,6 +280,10 @@ pub enum MessageContext { /// /// [`OffersMessage`]: crate::onion_message::offers::OffersMessage Offers(OffersContext), + /// Context specific to an [`AsyncPaymentsMessage`]. + /// + /// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage + AsyncPayments(AsyncPaymentsContext), /// Context specific to a [`CustomOnionMessageHandler::CustomMessage`]. /// /// [`CustomOnionMessageHandler::CustomMessage`]: crate::onion_message::messenger::CustomOnionMessageHandler::CustomMessage @@ -347,12 +351,57 @@ pub enum OffersContext { /// /// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash payment_hash: PaymentHash, + + /// A nonce used for authenticating that a received [`InvoiceError`] is for a valid + /// sent [`Bolt12Invoice`]. + /// + /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError + /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice + nonce: Nonce, + + /// Authentication code for the [`PaymentHash`], which should be checked when the context is + /// used to log the received [`InvoiceError`]. + /// + /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError + hmac: Hmac, + }, +} + +/// Contains data specific to an [`AsyncPaymentsMessage`]. +/// +/// [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage +#[derive(Clone, Debug)] +pub enum AsyncPaymentsContext { + /// Context contained within the reply [`BlindedMessagePath`] we put in outbound + /// [`HeldHtlcAvailable`] messages, provided back to us in corresponding [`ReleaseHeldHtlc`] + /// messages. + /// + /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable + /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc + OutboundPayment { + /// ID used when payment to the originating [`Offer`] was initiated. Useful for us to identify + /// which of our pending outbound payments should be released to its often-offline payee. + /// + /// [`Offer`]: crate::offers::offer::Offer + payment_id: PaymentId, + /// A nonce used for authenticating that a [`ReleaseHeldHtlc`] message is valid for a preceding + /// [`HeldHtlcAvailable`] message. + /// + /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc + /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable + nonce: Nonce, + /// Authentication code for the [`PaymentId`]. + /// + /// Prevents the recipient from being able to deanonymize us by creating a blinded path to us + /// containing the expected [`PaymentId`]. + hmac: Hmac, }, } impl_writeable_tlv_based_enum!(MessageContext, {0, Offers} => (), {1, Custom} => (), + {2, AsyncPayments} => (), ); impl_writeable_tlv_based_enum!(OffersContext, @@ -366,6 +415,16 @@ impl_writeable_tlv_based_enum!(OffersContext, }, (2, InboundPayment) => { (0, payment_hash, required), + (1, nonce, required), + (2, hmac, required) + }, +); + +impl_writeable_tlv_based_enum!(AsyncPaymentsContext, + (0, OutboundPayment) => { + (0, payment_id, required), + (2, nonce, required), + (4, hmac, required), }, ); diff --git a/lightning/src/chain/chainmonitor.rs b/lightning/src/chain/chainmonitor.rs index 82404ea0fa0..afd9df62851 100644 --- a/lightning/src/chain/chainmonitor.rs +++ b/lightning/src/chain/chainmonitor.rs @@ -997,35 +997,35 @@ mod tests { // back-to-back it doesn't fit into the neat walk commitment_signed_dance does. let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_first_raa, as_first_update) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); check_added_monitors!(nodes[1], 1); let bs_second_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_first_update); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_first_update); check_added_monitors!(nodes[1], 1); let bs_first_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage_2, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); expect_payment_path_successful!(nodes[0]); check_added_monitors!(nodes[0], 1); let (as_second_raa, as_second_update) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_update); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_second_update); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); expect_payment_path_successful!(nodes[0]); check_added_monitors!(nodes[0], 1); } diff --git a/lightning/src/crypto/chacha20.rs b/lightning/src/crypto/chacha20.rs index d1dcff1474c..cbe3e4e1062 100644 --- a/lightning/src/crypto/chacha20.rs +++ b/lightning/src/crypto/chacha20.rs @@ -20,20 +20,24 @@ mod real_chacha { type Output = u32x4; #[inline] fn add(self, rhs: u32x4) -> u32x4 { - u32x4(self.0.wrapping_add(rhs.0), - self.1.wrapping_add(rhs.1), - self.2.wrapping_add(rhs.2), - self.3.wrapping_add(rhs.3)) + u32x4( + self.0.wrapping_add(rhs.0), + self.1.wrapping_add(rhs.1), + self.2.wrapping_add(rhs.2), + self.3.wrapping_add(rhs.3), + ) } } impl ::core::ops::Sub for u32x4 { type Output = u32x4; #[inline] fn sub(self, rhs: u32x4) -> u32x4 { - u32x4(self.0.wrapping_sub(rhs.0), - self.1.wrapping_sub(rhs.1), - self.2.wrapping_sub(rhs.2), - self.3.wrapping_sub(rhs.3)) + u32x4( + self.0.wrapping_sub(rhs.0), + self.1.wrapping_sub(rhs.1), + self.2.wrapping_sub(rhs.2), + self.3.wrapping_sub(rhs.3), + ) } } impl ::core::ops::BitXor for u32x4 { @@ -60,44 +64,48 @@ mod real_chacha { impl u32x4 { #[inline] fn from_bytes(bytes: &[u8]) -> Self { - assert_eq!(bytes.len(), 4*4); - Self ( - u32::from_le_bytes(bytes[0*4..1*4].try_into().expect("len is 4")), - u32::from_le_bytes(bytes[1*4..2*4].try_into().expect("len is 4")), - u32::from_le_bytes(bytes[2*4..3*4].try_into().expect("len is 4")), - u32::from_le_bytes(bytes[3*4..4*4].try_into().expect("len is 4")), + assert_eq!(bytes.len(), 4 * 4); + Self( + u32::from_le_bytes(bytes[0 * 4..1 * 4].try_into().expect("len is 4")), + u32::from_le_bytes(bytes[1 * 4..2 * 4].try_into().expect("len is 4")), + u32::from_le_bytes(bytes[2 * 4..3 * 4].try_into().expect("len is 4")), + u32::from_le_bytes(bytes[3 * 4..4 * 4].try_into().expect("len is 4")), ) } } const BLOCK_SIZE: usize = 64; - #[derive(Clone,Copy)] + #[derive(Clone, Copy)] struct ChaChaState { a: u32x4, b: u32x4, c: u32x4, - d: u32x4 + d: u32x4, } #[derive(Copy)] pub struct ChaCha20 { - state : ChaChaState, - output : [u8; BLOCK_SIZE], - offset : usize, + state: ChaChaState, + output: [u8; BLOCK_SIZE], + offset: usize, } - impl Clone for ChaCha20 { fn clone(&self) -> ChaCha20 { *self } } + impl Clone for ChaCha20 { + fn clone(&self) -> ChaCha20 { + *self + } + } macro_rules! swizzle { ($b: expr, $c: expr, $d: expr) => {{ let u32x4(b10, b11, b12, b13) = $b; $b = u32x4(b11, b12, b13, b10); let u32x4(c10, c11, c12, c13) = $c; - $c = u32x4(c12, c13,c10, c11); + $c = u32x4(c12, c13, c10, c11); let u32x4(d10, d11, d12, d13) = $d; $d = u32x4(d13, d10, d11, d12); - }} + }}; } macro_rules! state_to_buffer { @@ -106,19 +114,14 @@ mod real_chacha { let u32x4(b1, b2, b3, b4) = $state.b; let u32x4(c1, c2, c3, c4) = $state.c; let u32x4(d1, d2, d3, d4) = $state.d; - let lens = [ - a1,a2,a3,a4, - b1,b2,b3,b4, - c1,c2,c3,c4, - d1,d2,d3,d4 - ]; + let lens = [a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4]; for i in 0..lens.len() { - $output[i*4..(i+1)*4].copy_from_slice(&lens[i].to_le_bytes()); + $output[i * 4..(i + 1) * 4].copy_from_slice(&lens[i].to_le_bytes()); } - }} + }}; } - macro_rules! round{ + macro_rules! round { ($state: expr) => {{ $state.a = $state.a + $state.b; rotate!($state.d, $state.a, 16); @@ -128,7 +131,7 @@ mod real_chacha { rotate!($state.d, $state.a, 8); $state.c = $state.c + $state.d; rotate!($state.b, $state.c, 7); - }} + }}; } macro_rules! rotate { @@ -137,7 +140,7 @@ mod real_chacha { let r = 32 - $rot; let right = v >> r; $a = (v << $rot) ^ right - }} + }}; } impl ChaCha20 { @@ -145,12 +148,16 @@ mod real_chacha { assert!(key.len() == 16 || key.len() == 32); assert!(nonce.len() == 8 || nonce.len() == 12); - ChaCha20{ state: ChaCha20::expand(key, nonce), output: [0u8; BLOCK_SIZE], offset: 64 } + ChaCha20 { state: ChaCha20::expand(key, nonce), output: [0u8; BLOCK_SIZE], offset: 64 } } /// Get one block from a ChaCha stream. pub fn get_single_block(key: &[u8; 32], nonce: &[u8; 16]) -> [u8; 32] { - let mut chacha = ChaCha20 { state: ChaCha20::expand(key, nonce), output: [0u8; BLOCK_SIZE], offset: 64 }; + let mut chacha = ChaCha20 { + state: ChaCha20::expand(key, nonce), + output: [0u8; BLOCK_SIZE], + offset: 64, + }; let mut chacha_bytes = [0; 32]; chacha.process_in_place(&mut chacha_bytes); chacha_bytes @@ -158,9 +165,7 @@ mod real_chacha { /// Encrypts `src` into `dest` using a single block from a ChaCha stream. Passing `dest` as /// `src` in a second call will decrypt it. - pub fn encrypt_single_block( - key: &[u8; 32], nonce: &[u8; 16], dest: &mut [u8], src: &[u8] - ) { + pub fn encrypt_single_block(key: &[u8; 32], nonce: &[u8; 16], dest: &mut [u8], src: &[u8]) { debug_assert_eq!(dest.len(), src.len()); debug_assert!(dest.len() <= 32); @@ -172,7 +177,7 @@ mod real_chacha { /// Same as `encrypt_single_block` only operates on a fixed-size input in-place. pub fn encrypt_single_block_in_place( - key: &[u8; 32], nonce: &[u8; 16], bytes: &mut [u8; 32] + key: &[u8; 32], nonce: &[u8; 16], bytes: &mut [u8; 32], ) { let block = ChaCha20::get_single_block(key, nonce); for i in 0..bytes.len() { @@ -184,7 +189,7 @@ mod real_chacha { let constant = match key.len() { 16 => b"expand 16-byte k", 32 => b"expand 32-byte k", - _ => unreachable!(), + _ => unreachable!(), }; ChaChaState { a: u32x4::from_bytes(&constant[0..16]), @@ -197,14 +202,14 @@ mod real_chacha { d: if nonce.len() == 16 { u32x4::from_bytes(&nonce[0..16]) } else if nonce.len() == 12 { - let mut nonce4 = [0; 4*4]; + let mut nonce4 = [0; 4 * 4]; nonce4[4..].copy_from_slice(nonce); u32x4::from_bytes(&nonce4) } else { - let mut nonce4 = [0; 4*4]; + let mut nonce4 = [0; 4 * 4]; nonce4[8..].copy_from_slice(nonce); u32x4::from_bytes(&nonce4) - } + }, } } @@ -312,15 +317,16 @@ mod fuzzy_chacha { } pub fn encrypt_single_block( - _key: &[u8; 32], _nonce: &[u8; 16], dest: &mut [u8], src: &[u8] + _key: &[u8; 32], _nonce: &[u8; 16], dest: &mut [u8], src: &[u8], ) { debug_assert_eq!(dest.len(), src.len()); debug_assert!(dest.len() <= 32); } pub fn encrypt_single_block_in_place( - _key: &[u8; 32], _nonce: &[u8; 16], _bytes: &mut [u8; 32] - ) {} + _key: &[u8; 32], _nonce: &[u8; 16], _bytes: &mut [u8; 32], + ) { + } pub fn process(&mut self, input: &[u8], output: &mut [u8]) { output.copy_from_slice(input); @@ -343,128 +349,103 @@ mod test { #[test] fn test_chacha20_256_tls_vectors() { struct TestVector { - key: [u8; 32], + key: [u8; 32], nonce: [u8; 8], keystream: Vec, } // taken from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04 - let test_vectors = vec!( - TestVector{ + let test_vectors = vec![ + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, + 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, + 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, + 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, + 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, - 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, - 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, - 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, - 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, - 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, - 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, - 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, + 0x8e, 0x3c, 0x96, 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, + 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, + 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, 0x53, 0xd7, 0x92, 0xb1, + 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, - 0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96, - 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, - 0x4f, 0x45, 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, - 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, 0xd2, - 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, - 0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81, - 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], + keystream: vec![ + 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, + 0x3f, 0x65, 0x3a, 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, + 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, + 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, 0x52, 0x77, 0x06, 0x2e, + 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ], - keystream: vec!( - 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, - 0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a, - 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, - 0x4f, 0xcb, 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, - 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, 0x45, - 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, - 0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e, - 0x44, 0x5f, 0x41, 0xe3, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, + 0xd3, 0x3b, 0x80, 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, + 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, + 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, 0x5d, 0xdc, 0x49, 0x7a, + 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, ], - nonce: [ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, - 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, - 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, - 0x33, 0x96, 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, - 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, 0x3c, - 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, - 0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d, - 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + ], + nonce: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07], + keystream: vec![ + 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, 0x82, 0x10, 0x5f, 0xfb, 0x64, + 0x0b, 0xb7, 0x75, 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, 0xec, 0x01, + 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, + 0x41, 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, 0x05, 0xd3, 0xbe, 0x59, + 0xea, 0x1c, 0x53, 0xf1, 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, 0x38, + 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, + 0xde, 0x66, 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, 0x89, 0xfb, 0x60, + 0xe8, 0x46, 0x29, 0xc9, 0xbd, 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, + 0x3e, 0xb9, 0xb3, 0xa4, 0xa4, 0x72, 0xf8, 0x2e, 0x09, 0xa7, 0xe7, 0x78, 0x49, + 0x2b, 0x56, 0x2e, 0xf7, 0x13, 0x0e, 0x88, 0xdf, 0xe0, 0x31, 0xc7, 0x9d, 0xb9, + 0xd4, 0xf7, 0xc7, 0xa8, 0x99, 0x15, 0x1b, 0x9a, 0x47, 0x50, 0x32, 0xb6, 0x3f, + 0xc3, 0x85, 0x24, 0x5f, 0xe0, 0x54, 0xe3, 0xdd, 0x5a, 0x97, 0xa5, 0xf5, 0x76, + 0xfe, 0x06, 0x40, 0x25, 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, 0x07, + 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, + 0xc9, 0xc4, 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, 0x0e, 0xaf, 0x46, + 0xf7, 0x6d, 0xad, 0x39, 0x79, 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, + 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, 0x94, 0xdf, 0x76, 0x28, 0xfe, + 0x4e, 0xaa, 0xf2, 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, 0xd0, 0xf9, + 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, + 0x7a, 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, ], - nonce: [ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 ], - keystream: vec!( - 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, - 0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75, - 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, - 0xec, 0x01, 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, - 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, 0x41, - 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, - 0x05, 0xd3, 0xbe, 0x59, 0xea, 0x1c, 0x53, 0xf1, - 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, - 0x38, 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, - 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, 0xde, 0x66, - 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, - 0x89, 0xfb, 0x60, 0xe8, 0x46, 0x29, 0xc9, 0xbd, - 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, - 0x3e, 0xb9, 0xb3, 0xa4, 0xa4, 0x72, 0xf8, 0x2e, - 0x09, 0xa7, 0xe7, 0x78, 0x49, 0x2b, 0x56, 0x2e, - 0xf7, 0x13, 0x0e, 0x88, 0xdf, 0xe0, 0x31, 0xc7, - 0x9d, 0xb9, 0xd4, 0xf7, 0xc7, 0xa8, 0x99, 0x15, - 0x1b, 0x9a, 0x47, 0x50, 0x32, 0xb6, 0x3f, 0xc3, - 0x85, 0x24, 0x5f, 0xe0, 0x54, 0xe3, 0xdd, 0x5a, - 0x97, 0xa5, 0xf5, 0x76, 0xfe, 0x06, 0x40, 0x25, - 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, - 0x07, 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, - 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, 0xc9, 0xc4, - 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, - 0x0e, 0xaf, 0x46, 0xf7, 0x6d, 0xad, 0x39, 0x79, - 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, - 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, - 0x94, 0xdf, 0x76, 0x28, 0xfe, 0x4e, 0xaa, 0xf2, - 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, - 0xd0, 0xf9, 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, - 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, 0x7a, - 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, - ), }, - ); + ]; for tv in test_vectors.iter() { let mut c = ChaCha20::new(&tv.key, &tv.nonce); @@ -478,128 +459,103 @@ mod test { #[test] fn test_chacha20_256_tls_vectors_96_nonce() { struct TestVector { - key: [u8; 32], + key: [u8; 32], nonce: [u8; 12], keystream: Vec, } // taken from http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305-04 - let test_vectors = vec!( - TestVector{ + let test_vectors = vec![ + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, 0x40, 0x5d, 0x6a, 0xe5, 0x53, + 0x86, 0xbd, 0x28, 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, 0xa8, 0x36, + 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, + 0x8d, 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, 0x6a, 0x43, 0xb8, 0xf4, + 0x15, 0x18, 0xa1, 0x1c, 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0x76, 0xb8, 0xe0, 0xad, 0xa0, 0xf1, 0x3d, 0x90, - 0x40, 0x5d, 0x6a, 0xe5, 0x53, 0x86, 0xbd, 0x28, - 0xbd, 0xd2, 0x19, 0xb8, 0xa0, 0x8d, 0xed, 0x1a, - 0xa8, 0x36, 0xef, 0xcc, 0x8b, 0x77, 0x0d, 0xc7, - 0xda, 0x41, 0x59, 0x7c, 0x51, 0x57, 0x48, 0x8d, - 0x77, 0x24, 0xe0, 0x3f, 0xb8, 0xd8, 0x4a, 0x37, - 0x6a, 0x43, 0xb8, 0xf4, 0x15, 0x18, 0xa1, 0x1c, - 0xc3, 0x87, 0xb6, 0x69, 0xb2, 0xee, 0x65, 0x86, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, 0xd7, 0x73, 0x6e, 0x7b, 0x20, + 0x8e, 0x3c, 0x96, 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, 0x4f, 0x45, + 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, + 0xd2, 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, 0x53, 0xd7, 0x92, 0xb1, + 0xc4, 0x3f, 0xea, 0x81, 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0x45, 0x40, 0xf0, 0x5a, 0x9f, 0x1f, 0xb2, 0x96, - 0xd7, 0x73, 0x6e, 0x7b, 0x20, 0x8e, 0x3c, 0x96, - 0xeb, 0x4f, 0xe1, 0x83, 0x46, 0x88, 0xd2, 0x60, - 0x4f, 0x45, 0x09, 0x52, 0xed, 0x43, 0x2d, 0x41, - 0xbb, 0xe2, 0xa0, 0xb6, 0xea, 0x75, 0x66, 0xd2, - 0xa5, 0xd1, 0xe7, 0xe2, 0x0d, 0x42, 0xaf, 0x2c, - 0x53, 0xd7, 0x92, 0xb1, 0xc4, 0x3f, 0xea, 0x81, - 0x7e, 0x9a, 0xd2, 0x75, 0xae, 0x54, 0x69, 0x63, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01], + keystream: vec![ + 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, 0xe7, 0x86, 0xdc, 0x63, 0x97, + 0x3f, 0x65, 0x3a, 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, 0x4f, 0xcb, + 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, + 0x45, 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, 0x52, 0x77, 0x06, 0x2e, + 0xb7, 0xa0, 0x43, 0x3e, 0x44, 0x5f, 0x41, 0xe3, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ], - keystream: vec!( - 0xde, 0x9c, 0xba, 0x7b, 0xf3, 0xd6, 0x9e, 0xf5, - 0xe7, 0x86, 0xdc, 0x63, 0x97, 0x3f, 0x65, 0x3a, - 0x0b, 0x49, 0xe0, 0x15, 0xad, 0xbf, 0xf7, 0x13, - 0x4f, 0xcb, 0x7d, 0xf1, 0x37, 0x82, 0x10, 0x31, - 0xe8, 0x5a, 0x05, 0x02, 0x78, 0xa7, 0x08, 0x45, - 0x27, 0x21, 0x4f, 0x73, 0xef, 0xc7, 0xfa, 0x5b, - 0x52, 0x77, 0x06, 0x2e, 0xb7, 0xa0, 0x43, 0x3e, - 0x44, 0x5f, 0x41, 0xe3, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + keystream: vec![ + 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, 0xf5, 0xcf, 0x35, 0xbd, 0x3d, + 0xd3, 0x3b, 0x80, 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, 0x33, 0x96, + 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, + 0x3c, 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, 0x5d, 0xdc, 0x49, 0x7a, + 0x0b, 0x46, 0x6e, 0x7d, 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, ], - nonce: [ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ], - keystream: vec!( - 0xef, 0x3f, 0xdf, 0xd6, 0xc6, 0x15, 0x78, 0xfb, - 0xf5, 0xcf, 0x35, 0xbd, 0x3d, 0xd3, 0x3b, 0x80, - 0x09, 0x63, 0x16, 0x34, 0xd2, 0x1e, 0x42, 0xac, - 0x33, 0x96, 0x0b, 0xd1, 0x38, 0xe5, 0x0d, 0x32, - 0x11, 0x1e, 0x4c, 0xaf, 0x23, 0x7e, 0xe5, 0x3c, - 0xa8, 0xad, 0x64, 0x26, 0x19, 0x4a, 0x88, 0x54, - 0x5d, 0xdc, 0x49, 0x7a, 0x0b, 0x46, 0x6e, 0x7d, - 0x6b, 0xbd, 0xb0, 0x04, 0x1b, 0x2f, 0x58, 0x6b, - ), - }, TestVector{ + }, + TestVector { key: [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, + 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + ], + nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07], + keystream: vec![ + 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, 0x82, 0x10, 0x5f, 0xfb, 0x64, + 0x0b, 0xb7, 0x75, 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, 0xec, 0x01, + 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, + 0x41, 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, 0x05, 0xd3, 0xbe, 0x59, + 0xea, 0x1c, 0x53, 0xf1, 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, 0x38, + 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, + 0xde, 0x66, 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, 0x89, 0xfb, 0x60, + 0xe8, 0x46, 0x29, 0xc9, 0xbd, 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, + 0x3e, 0xb9, 0xb3, 0xa4, 0xa4, 0x72, 0xf8, 0x2e, 0x09, 0xa7, 0xe7, 0x78, 0x49, + 0x2b, 0x56, 0x2e, 0xf7, 0x13, 0x0e, 0x88, 0xdf, 0xe0, 0x31, 0xc7, 0x9d, 0xb9, + 0xd4, 0xf7, 0xc7, 0xa8, 0x99, 0x15, 0x1b, 0x9a, 0x47, 0x50, 0x32, 0xb6, 0x3f, + 0xc3, 0x85, 0x24, 0x5f, 0xe0, 0x54, 0xe3, 0xdd, 0x5a, 0x97, 0xa5, 0xf5, 0x76, + 0xfe, 0x06, 0x40, 0x25, 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, 0x07, + 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, + 0xc9, 0xc4, 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, 0x0e, 0xaf, 0x46, + 0xf7, 0x6d, 0xad, 0x39, 0x79, 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, + 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, 0x94, 0xdf, 0x76, 0x28, 0xfe, + 0x4e, 0xaa, 0xf2, 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, 0xd0, 0xf9, + 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, + 0x7a, 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, ], - nonce: [0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 ], - keystream: vec!( - 0xf7, 0x98, 0xa1, 0x89, 0xf1, 0x95, 0xe6, 0x69, - 0x82, 0x10, 0x5f, 0xfb, 0x64, 0x0b, 0xb7, 0x75, - 0x7f, 0x57, 0x9d, 0xa3, 0x16, 0x02, 0xfc, 0x93, - 0xec, 0x01, 0xac, 0x56, 0xf8, 0x5a, 0xc3, 0xc1, - 0x34, 0xa4, 0x54, 0x7b, 0x73, 0x3b, 0x46, 0x41, - 0x30, 0x42, 0xc9, 0x44, 0x00, 0x49, 0x17, 0x69, - 0x05, 0xd3, 0xbe, 0x59, 0xea, 0x1c, 0x53, 0xf1, - 0x59, 0x16, 0x15, 0x5c, 0x2b, 0xe8, 0x24, 0x1a, - 0x38, 0x00, 0x8b, 0x9a, 0x26, 0xbc, 0x35, 0x94, - 0x1e, 0x24, 0x44, 0x17, 0x7c, 0x8a, 0xde, 0x66, - 0x89, 0xde, 0x95, 0x26, 0x49, 0x86, 0xd9, 0x58, - 0x89, 0xfb, 0x60, 0xe8, 0x46, 0x29, 0xc9, 0xbd, - 0x9a, 0x5a, 0xcb, 0x1c, 0xc1, 0x18, 0xbe, 0x56, - 0x3e, 0xb9, 0xb3, 0xa4, 0xa4, 0x72, 0xf8, 0x2e, - 0x09, 0xa7, 0xe7, 0x78, 0x49, 0x2b, 0x56, 0x2e, - 0xf7, 0x13, 0x0e, 0x88, 0xdf, 0xe0, 0x31, 0xc7, - 0x9d, 0xb9, 0xd4, 0xf7, 0xc7, 0xa8, 0x99, 0x15, - 0x1b, 0x9a, 0x47, 0x50, 0x32, 0xb6, 0x3f, 0xc3, - 0x85, 0x24, 0x5f, 0xe0, 0x54, 0xe3, 0xdd, 0x5a, - 0x97, 0xa5, 0xf5, 0x76, 0xfe, 0x06, 0x40, 0x25, - 0xd3, 0xce, 0x04, 0x2c, 0x56, 0x6a, 0xb2, 0xc5, - 0x07, 0xb1, 0x38, 0xdb, 0x85, 0x3e, 0x3d, 0x69, - 0x59, 0x66, 0x09, 0x96, 0x54, 0x6c, 0xc9, 0xc4, - 0xa6, 0xea, 0xfd, 0xc7, 0x77, 0xc0, 0x40, 0xd7, - 0x0e, 0xaf, 0x46, 0xf7, 0x6d, 0xad, 0x39, 0x79, - 0xe5, 0xc5, 0x36, 0x0c, 0x33, 0x17, 0x16, 0x6a, - 0x1c, 0x89, 0x4c, 0x94, 0xa3, 0x71, 0x87, 0x6a, - 0x94, 0xdf, 0x76, 0x28, 0xfe, 0x4e, 0xaa, 0xf2, - 0xcc, 0xb2, 0x7d, 0x5a, 0xaa, 0xe0, 0xad, 0x7a, - 0xd0, 0xf9, 0xd4, 0xb6, 0xad, 0x3b, 0x54, 0x09, - 0x87, 0x46, 0xd4, 0x52, 0x4d, 0x38, 0x40, 0x7a, - 0x6d, 0xeb, 0x3a, 0xb7, 0x8f, 0xab, 0x78, 0xc9, - ), }, - ); + ]; for tv in test_vectors.iter() { let mut c = ChaCha20::new(&tv.key, &tv.nonce); @@ -616,13 +572,13 @@ mod test { // using a 12-byte nonce, with the block starting at the counter offset given by the remaining 4 // bytes. let key = [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, ]; let nonce_16bytes = [ - 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b + 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, ]; let counter_pos = &nonce_16bytes[..4]; let nonce_12bytes = &nonce_16bytes[4..]; @@ -640,14 +596,13 @@ mod test { #[test] fn encrypt_single_block() { let key = [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, ]; let nonce = [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, ]; let bytes = [1; 32]; @@ -663,14 +618,13 @@ mod test { #[test] fn encrypt_single_block_in_place() { let key = [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, ]; let nonce = [ - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, - 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, ]; let unencrypted_bytes = [1; 32]; let mut bytes = unencrypted_bytes; diff --git a/lightning/src/crypto/chacha20poly1305rfc.rs b/lightning/src/crypto/chacha20poly1305rfc.rs index 76d6040c224..f1c261cb1f1 100644 --- a/lightning/src/crypto/chacha20poly1305rfc.rs +++ b/lightning/src/crypto/chacha20poly1305rfc.rs @@ -13,8 +13,8 @@ #[cfg(not(fuzzing))] mod real_chachapoly { use super::super::chacha20::ChaCha20; - use super::super::poly1305::Poly1305; use super::super::fixed_time_eq; + use super::super::poly1305::Poly1305; #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { @@ -70,7 +70,9 @@ mod real_chachapoly { self.mac.raw_result(out_tag); } - pub fn encrypt_full_message_in_place(&mut self, input_output: &mut [u8], out_tag: &mut [u8]) { + pub fn encrypt_full_message_in_place( + &mut self, input_output: &mut [u8], out_tag: &mut [u8], + ) { self.encrypt_in_place(input_output); self.finish_and_get_tag(out_tag); } @@ -98,7 +100,9 @@ mod real_chachapoly { /// Decrypt the `input`, checking the given `tag` prior to writing the decrypted contents /// into `output`. Note that, because `output` is not touched until the `tag` is checked, /// this decryption is *variable time*. - pub fn variable_time_decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> Result<(), ()> { + pub fn variable_time_decrypt( + &mut self, input: &[u8], output: &mut [u8], tag: &[u8], + ) -> Result<(), ()> { assert!(input.len() == output.len()); assert!(!self.finished); @@ -111,7 +115,7 @@ mod real_chachapoly { self.mac.input(&self.aad_len.to_le_bytes()); self.mac.input(&(self.data_len as u64).to_le_bytes()); - let mut calc_tag = [0u8; 16]; + let mut calc_tag = [0u8; 16]; self.mac.raw_result(&mut calc_tag); if fixed_time_eq(&calc_tag, tag) { self.cipher.process(input, output); @@ -121,9 +125,15 @@ mod real_chachapoly { } } - pub fn check_decrypt_in_place(&mut self, input_output: &mut [u8], tag: &[u8]) -> Result<(), ()> { + pub fn check_decrypt_in_place( + &mut self, input_output: &mut [u8], tag: &[u8], + ) -> Result<(), ()> { self.decrypt_in_place(input_output); - if self.finish_and_check_tag(tag) { Ok(()) } else { Err(()) } + if self.finish_and_check_tag(tag) { + Ok(()) + } else { + Err(()) + } } /// Decrypt in place, without checking the tag. Use `finish_and_check_tag` to check it @@ -146,7 +156,7 @@ mod real_chachapoly { self.mac.input(&self.aad_len.to_le_bytes()); self.mac.input(&(self.data_len as u64).to_le_bytes()); - let mut calc_tag = [0u8; 16]; + let mut calc_tag = [0u8; 16]; self.mac.raw_result(&mut calc_tag); if fixed_time_eq(&calc_tag, tag) { true @@ -177,10 +187,7 @@ mod fuzzy_chachapoly { let mut tag = [0; 16]; tag.copy_from_slice(&key[0..16]); - ChaCha20Poly1305RFC { - tag, - finished: false, - } + ChaCha20Poly1305RFC { tag, finished: false } } pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { @@ -192,7 +199,9 @@ mod fuzzy_chachapoly { self.finished = true; } - pub fn encrypt_full_message_in_place(&mut self, input_output: &mut [u8], out_tag: &mut [u8]) { + pub fn encrypt_full_message_in_place( + &mut self, input_output: &mut [u8], out_tag: &mut [u8], + ) { self.encrypt_in_place(input_output); self.finish_and_get_tag(out_tag); } @@ -207,19 +216,29 @@ mod fuzzy_chachapoly { self.finished = true; } - pub fn variable_time_decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> Result<(), ()> { + pub fn variable_time_decrypt( + &mut self, input: &[u8], output: &mut [u8], tag: &[u8], + ) -> Result<(), ()> { assert!(input.len() == output.len()); assert!(self.finished == false); - if tag[..] != self.tag[..] { return Err(()); } + if tag[..] != self.tag[..] { + return Err(()); + } output.copy_from_slice(input); self.finished = true; Ok(()) } - pub fn check_decrypt_in_place(&mut self, input_output: &mut [u8], tag: &[u8]) -> Result<(), ()> { + pub fn check_decrypt_in_place( + &mut self, input_output: &mut [u8], tag: &[u8], + ) -> Result<(), ()> { self.decrypt_in_place(input_output); - if self.finish_and_check_tag(tag) { Ok(()) } else { Err(()) } + if self.finish_and_check_tag(tag) { + Ok(()) + } else { + Err(()) + } } pub(in super::super) fn decrypt_in_place(&mut self, _input: &mut [u8]) { @@ -227,7 +246,9 @@ mod fuzzy_chachapoly { } pub(in super::super) fn finish_and_check_tag(&mut self, tag: &[u8]) -> bool { - if tag[..] != self.tag[..] { return false; } + if tag[..] != self.tag[..] { + return false; + } self.finished = true; true } diff --git a/lightning/src/crypto/mod.rs b/lightning/src/crypto/mod.rs index b4f5af8f119..4dc851a3683 100644 --- a/lightning/src/crypto/mod.rs +++ b/lightning/src/crypto/mod.rs @@ -2,8 +2,8 @@ use bitcoin::hashes::cmp::fixed_time_eq; pub(crate) mod chacha20; +pub(crate) mod chacha20poly1305rfc; #[cfg(not(fuzzing))] pub(crate) mod poly1305; -pub(crate) mod chacha20poly1305rfc; pub(crate) mod streams; pub(crate) mod utils; diff --git a/lightning/src/crypto/poly1305.rs b/lightning/src/crypto/poly1305.rs index 7b744912561..6ac1c6c9694 100644 --- a/lightning/src/crypto/poly1305.rs +++ b/lightning/src/crypto/poly1305.rs @@ -13,25 +13,33 @@ use crate::prelude::*; #[derive(Clone, Copy)] pub struct Poly1305 { - r : [u32; 5], - h : [u32; 5], - pad : [u32; 4], - leftover : usize, - buffer : [u8; 16], - finalized : bool, + r: [u32; 5], + h: [u32; 5], + pad: [u32; 4], + leftover: usize, + buffer: [u8; 16], + finalized: bool, } impl Poly1305 { pub fn new(key: &[u8]) -> Poly1305 { assert!(key.len() == 32); - let mut poly = Poly1305{ r: [0u32; 5], h: [0u32; 5], pad: [0u32; 4], leftover: 0, buffer: [0u8; 16], finalized: false }; + let mut poly = Poly1305 { + r: [0u32; 5], + h: [0u32; 5], + pad: [0u32; 4], + leftover: 0, + buffer: [0u8; 16], + finalized: false, + }; // r &= 0xffffffc0ffffffc0ffffffc0fffffff - poly.r[0] = (u32::from_le_bytes(key[ 0.. 4].try_into().expect("len is 4")) ) & 0x3ffffff; - poly.r[1] = (u32::from_le_bytes(key[ 3.. 7].try_into().expect("len is 4")) >> 2) & 0x3ffff03; - poly.r[2] = (u32::from_le_bytes(key[ 6..10].try_into().expect("len is 4")) >> 4) & 0x3ffc0ff; - poly.r[3] = (u32::from_le_bytes(key[ 9..13].try_into().expect("len is 4")) >> 6) & 0x3f03fff; - poly.r[4] = (u32::from_le_bytes(key[12..16].try_into().expect("len is 4")) >> 8) & 0x00fffff; + poly.r[0] = (u32::from_le_bytes(key[0..4].try_into().expect("len is 4"))) & 0x3ffffff; + poly.r[1] = (u32::from_le_bytes(key[3..7].try_into().expect("len is 4")) >> 2) & 0x3ffff03; + poly.r[2] = (u32::from_le_bytes(key[6..10].try_into().expect("len is 4")) >> 4) & 0x3ffc0ff; + poly.r[3] = (u32::from_le_bytes(key[9..13].try_into().expect("len is 4")) >> 6) & 0x3f03fff; + poly.r[4] = + (u32::from_le_bytes(key[12..16].try_into().expect("len is 4")) >> 8) & 0x00fffff; poly.pad[0] = u32::from_le_bytes(key[16..20].try_into().expect("len is 4")); poly.pad[1] = u32::from_le_bytes(key[20..24].try_into().expect("len is 4")); @@ -42,7 +50,7 @@ impl Poly1305 { } fn block(&mut self, m: &[u8]) { - let hibit : u32 = if self.finalized { 0 } else { 1 << 24 }; + let hibit: u32 = if self.finalized { 0 } else { 1 << 24 }; let r0 = self.r[0]; let r1 = self.r[1]; @@ -62,27 +70,58 @@ impl Poly1305 { let mut h4 = self.h[4]; // h += m - h0 += (u32::from_le_bytes(m[ 0.. 4].try_into().expect("len is 4")) ) & 0x3ffffff; - h1 += (u32::from_le_bytes(m[ 3.. 7].try_into().expect("len is 4")) >> 2) & 0x3ffffff; - h2 += (u32::from_le_bytes(m[ 6..10].try_into().expect("len is 4")) >> 4) & 0x3ffffff; - h3 += (u32::from_le_bytes(m[ 9..13].try_into().expect("len is 4")) >> 6) & 0x3ffffff; + h0 += (u32::from_le_bytes(m[0..4].try_into().expect("len is 4"))) & 0x3ffffff; + h1 += (u32::from_le_bytes(m[3..7].try_into().expect("len is 4")) >> 2) & 0x3ffffff; + h2 += (u32::from_le_bytes(m[6..10].try_into().expect("len is 4")) >> 4) & 0x3ffffff; + h3 += (u32::from_le_bytes(m[9..13].try_into().expect("len is 4")) >> 6) & 0x3ffffff; h4 += (u32::from_le_bytes(m[12..16].try_into().expect("len is 4")) >> 8) | hibit; // h *= r - let d0 = (h0 as u64 * r0 as u64) + (h1 as u64 * s4 as u64) + (h2 as u64 * s3 as u64) + (h3 as u64 * s2 as u64) + (h4 as u64 * s1 as u64); - let mut d1 = (h0 as u64 * r1 as u64) + (h1 as u64 * r0 as u64) + (h2 as u64 * s4 as u64) + (h3 as u64 * s3 as u64) + (h4 as u64 * s2 as u64); - let mut d2 = (h0 as u64 * r2 as u64) + (h1 as u64 * r1 as u64) + (h2 as u64 * r0 as u64) + (h3 as u64 * s4 as u64) + (h4 as u64 * s3 as u64); - let mut d3 = (h0 as u64 * r3 as u64) + (h1 as u64 * r2 as u64) + (h2 as u64 * r1 as u64) + (h3 as u64 * r0 as u64) + (h4 as u64 * s4 as u64); - let mut d4 = (h0 as u64 * r4 as u64) + (h1 as u64 * r3 as u64) + (h2 as u64 * r2 as u64) + (h3 as u64 * r1 as u64) + (h4 as u64 * r0 as u64); + let d0 = (h0 as u64 * r0 as u64) + + (h1 as u64 * s4 as u64) + + (h2 as u64 * s3 as u64) + + (h3 as u64 * s2 as u64) + + (h4 as u64 * s1 as u64); + let mut d1 = (h0 as u64 * r1 as u64) + + (h1 as u64 * r0 as u64) + + (h2 as u64 * s4 as u64) + + (h3 as u64 * s3 as u64) + + (h4 as u64 * s2 as u64); + let mut d2 = (h0 as u64 * r2 as u64) + + (h1 as u64 * r1 as u64) + + (h2 as u64 * r0 as u64) + + (h3 as u64 * s4 as u64) + + (h4 as u64 * s3 as u64); + let mut d3 = (h0 as u64 * r3 as u64) + + (h1 as u64 * r2 as u64) + + (h2 as u64 * r1 as u64) + + (h3 as u64 * r0 as u64) + + (h4 as u64 * s4 as u64); + let mut d4 = (h0 as u64 * r4 as u64) + + (h1 as u64 * r3 as u64) + + (h2 as u64 * r2 as u64) + + (h3 as u64 * r1 as u64) + + (h4 as u64 * r0 as u64); // (partial) h %= p - let mut c : u32; - c = (d0 >> 26) as u32; h0 = d0 as u32 & 0x3ffffff; - d1 += c as u64; c = (d1 >> 26) as u32; h1 = d1 as u32 & 0x3ffffff; - d2 += c as u64; c = (d2 >> 26) as u32; h2 = d2 as u32 & 0x3ffffff; - d3 += c as u64; c = (d3 >> 26) as u32; h3 = d3 as u32 & 0x3ffffff; - d4 += c as u64; c = (d4 >> 26) as u32; h4 = d4 as u32 & 0x3ffffff; - h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff; + let mut c: u32; + c = (d0 >> 26) as u32; + h0 = d0 as u32 & 0x3ffffff; + d1 += c as u64; + c = (d1 >> 26) as u32; + h1 = d1 as u32 & 0x3ffffff; + d2 += c as u64; + c = (d2 >> 26) as u32; + h2 = d2 as u32 & 0x3ffffff; + d3 += c as u64; + c = (d3 >> 26) as u32; + h3 = d3 as u32 & 0x3ffffff; + d4 += c as u64; + c = (d4 >> 26) as u32; + h4 = d4 as u32 & 0x3ffffff; + h0 += c * 5; + c = h0 >> 26; + h0 &= 0x3ffffff; h1 += c; self.h[0] = h0; @@ -95,7 +134,7 @@ impl Poly1305 { pub fn finish(&mut self) { if self.leftover > 0 { self.buffer[self.leftover] = 1; - for i in self.leftover+1..16 { + for i in self.leftover + 1..16 { self.buffer[i] = 0; } self.finalized = true; @@ -110,19 +149,36 @@ impl Poly1305 { let mut h3 = self.h[3]; let mut h4 = self.h[4]; - let mut c : u32; - c = h1 >> 26; h1 &= 0x3ffffff; - h2 += c; c = h2 >> 26; h2 &= 0x3ffffff; - h3 += c; c = h3 >> 26; h3 &= 0x3ffffff; - h4 += c; c = h4 >> 26; h4 &= 0x3ffffff; - h0 += c * 5; c = h0 >> 26; h0 &= 0x3ffffff; - h1 += c; + let mut c: u32; + c = h1 >> 26; + h1 &= 0x3ffffff; + h2 += c; + c = h2 >> 26; + h2 &= 0x3ffffff; + h3 += c; + c = h3 >> 26; + h3 &= 0x3ffffff; + h4 += c; + c = h4 >> 26; + h4 &= 0x3ffffff; + h0 += c * 5; + c = h0 >> 26; + h0 &= 0x3ffffff; + h1 += c; // compute h + -p - let mut g0 = h0.wrapping_add(5); c = g0 >> 26; g0 &= 0x3ffffff; - let mut g1 = h1.wrapping_add(c); c = g1 >> 26; g1 &= 0x3ffffff; - let mut g2 = h2.wrapping_add(c); c = g2 >> 26; g2 &= 0x3ffffff; - let mut g3 = h3.wrapping_add(c); c = g3 >> 26; g3 &= 0x3ffffff; + let mut g0 = h0.wrapping_add(5); + c = g0 >> 26; + g0 &= 0x3ffffff; + let mut g1 = h1.wrapping_add(c); + c = g1 >> 26; + g1 &= 0x3ffffff; + let mut g2 = h2.wrapping_add(c); + c = g2 >> 26; + g2 &= 0x3ffffff; + let mut g3 = h3.wrapping_add(c); + c = g3 >> 26; + g3 &= 0x3ffffff; let mut g4 = h4.wrapping_add(c).wrapping_sub(1 << 26); // select h if h < p, or h + -p if h >= p @@ -140,17 +196,21 @@ impl Poly1305 { h4 = (h4 & mask) | g4; // h = h % (2^128) - h0 = ((h0 ) | (h1 << 26)) & 0xffffffff; - h1 = ((h1 >> 6) | (h2 << 20)) & 0xffffffff; + h0 = ((h0) | (h1 << 26)) & 0xffffffff; + h1 = ((h1 >> 6) | (h2 << 20)) & 0xffffffff; h2 = ((h2 >> 12) | (h3 << 14)) & 0xffffffff; - h3 = ((h3 >> 18) | (h4 << 8)) & 0xffffffff; + h3 = ((h3 >> 18) | (h4 << 8)) & 0xffffffff; // h = mac = (h + pad) % (2^128) - let mut f : u64; - f = h0 as u64 + self.pad[0] as u64 ; h0 = f as u32; - f = h1 as u64 + self.pad[1] as u64 + (f >> 32); h1 = f as u32; - f = h2 as u64 + self.pad[2] as u64 + (f >> 32); h2 = f as u32; - f = h3 as u64 + self.pad[3] as u64 + (f >> 32); h3 = f as u32; + let mut f: u64; + f = h0 as u64 + self.pad[0] as u64; + h0 = f as u32; + f = h1 as u64 + self.pad[1] as u64 + (f >> 32); + h1 = f as u32; + f = h2 as u64 + self.pad[2] as u64 + (f >> 32); + h2 = f as u32; + f = h3 as u64 + self.pad[3] as u64 + (f >> 32); + h3 = f as u32; self.h[0] = h0; self.h[1] = h1; @@ -165,7 +225,7 @@ impl Poly1305 { if self.leftover > 0 { let want = min(16 - self.leftover, m.len()); for i in 0..want { - self.buffer[self.leftover+i] = m[i]; + self.buffer[self.leftover + i] = m[i]; } m = &m[want..]; self.leftover += want; @@ -194,7 +254,7 @@ impl Poly1305 { pub fn raw_result(&mut self, output: &mut [u8]) { assert!(output.len() >= 16); - if !self.finalized{ + if !self.finalized { self.finish(); } output[0..4].copy_from_slice(&self.h[0].to_le_bytes()); @@ -219,35 +279,27 @@ mod test { #[test] fn test_nacl_vector() { let key = [ - 0xee,0xa6,0xa7,0x25,0x1c,0x1e,0x72,0x91, - 0x6d,0x11,0xc2,0xcb,0x21,0x4d,0x3c,0x25, - 0x25,0x39,0x12,0x1d,0x8e,0x23,0x4e,0x65, - 0x2d,0x65,0x1f,0xa4,0xc8,0xcf,0xf8,0x80, + 0xee, 0xa6, 0xa7, 0x25, 0x1c, 0x1e, 0x72, 0x91, 0x6d, 0x11, 0xc2, 0xcb, 0x21, 0x4d, + 0x3c, 0x25, 0x25, 0x39, 0x12, 0x1d, 0x8e, 0x23, 0x4e, 0x65, 0x2d, 0x65, 0x1f, 0xa4, + 0xc8, 0xcf, 0xf8, 0x80, ]; let msg = [ - 0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73, - 0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce, - 0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4, - 0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a, - 0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b, - 0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72, - 0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2, - 0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38, - 0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a, - 0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae, - 0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea, - 0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda, - 0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde, - 0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3, - 0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6, - 0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74, - 0xe3,0x55,0xa5, + 0x8e, 0x99, 0x3b, 0x9f, 0x48, 0x68, 0x12, 0x73, 0xc2, 0x96, 0x50, 0xba, 0x32, 0xfc, + 0x76, 0xce, 0x48, 0x33, 0x2e, 0xa7, 0x16, 0x4d, 0x96, 0xa4, 0x47, 0x6f, 0xb8, 0xc5, + 0x31, 0xa1, 0x18, 0x6a, 0xc0, 0xdf, 0xc1, 0x7c, 0x98, 0xdc, 0xe8, 0x7b, 0x4d, 0xa7, + 0xf0, 0x11, 0xec, 0x48, 0xc9, 0x72, 0x71, 0xd2, 0xc2, 0x0f, 0x9b, 0x92, 0x8f, 0xe2, + 0x27, 0x0d, 0x6f, 0xb8, 0x63, 0xd5, 0x17, 0x38, 0xb4, 0x8e, 0xee, 0xe3, 0x14, 0xa7, + 0xcc, 0x8a, 0xb9, 0x32, 0x16, 0x45, 0x48, 0xe5, 0x26, 0xae, 0x90, 0x22, 0x43, 0x68, + 0x51, 0x7a, 0xcf, 0xea, 0xbd, 0x6b, 0xb3, 0x73, 0x2b, 0xc0, 0xe9, 0xda, 0x99, 0x83, + 0x2b, 0x61, 0xca, 0x01, 0xb6, 0xde, 0x56, 0x24, 0x4a, 0x9e, 0x88, 0xd5, 0xf9, 0xb3, + 0x79, 0x73, 0xf6, 0x22, 0xa4, 0x3d, 0x14, 0xa6, 0x59, 0x9b, 0x1f, 0x65, 0x4c, 0xb4, + 0x5a, 0x74, 0xe3, 0x55, 0xa5, ]; let expected = [ - 0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5, - 0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9, + 0xf3, 0xff, 0xc7, 0x70, 0x3f, 0x94, 0x00, 0xe5, 0x2a, 0x7d, 0xfb, 0x4b, 0x3d, 0x33, + 0x05, 0xd9, ]; let mut mac = [0u8; 16]; @@ -273,20 +325,19 @@ mod test { #[test] fn donna_self_test() { let wrap_key = [ - 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, ]; let wrap_msg = [ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, ]; let wrap_mac = [ - 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, ]; let mut mac = [0u8; 16]; @@ -294,15 +345,14 @@ mod test { assert_eq!(&mac[..], &wrap_mac[..]); let total_key = [ - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff, - 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, ]; let total_mac = [ - 0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, - 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, 0x3d, 0x39, + 0x64, 0xaf, 0xe2, 0xe8, 0xd6, 0xad, 0x7b, 0xbd, 0xd2, 0x87, 0xf9, 0x7c, 0x44, 0x62, + 0x3d, 0x39, ]; let mut tpoly = Poly1305::new(&total_key); @@ -323,17 +373,17 @@ mod test { let key = b"this is 32-byte key for Poly1305"; let msg = [0u8; 32]; let expected = [ - 0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6, - 0xc2, 0x6b, 0x33, 0xb9, 0x1c, 0xcc, 0x03, 0x07, + 0x49, 0xec, 0x78, 0x09, 0x0e, 0x48, 0x1e, 0xc6, 0xc2, 0x6b, 0x33, 0xb9, 0x1c, 0xcc, + 0x03, 0x07, ]; let mut mac = [0u8; 16]; poly1305(key, &msg, &mut mac); assert_eq!(&mac[..], &expected[..]); let msg = b"Hello world!"; - let expected= [ - 0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16, - 0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, 0xb2, 0xf0, + let expected = [ + 0xa6, 0xf7, 0x45, 0x00, 0x8f, 0x81, 0xc9, 0x16, 0xa2, 0x0d, 0xcc, 0x74, 0xee, 0xf2, + 0xb2, 0xf0, ]; poly1305(key, msg, &mut mac); assert_eq!(&mac[..], &expected[..]); diff --git a/lightning/src/crypto/streams.rs b/lightning/src/crypto/streams.rs index 7287eed84dc..9c7df314685 100644 --- a/lightning/src/crypto/streams.rs +++ b/lightning/src/crypto/streams.rs @@ -1,9 +1,11 @@ use crate::crypto::chacha20::ChaCha20; use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC; -use crate::ln::msgs::DecodeError; -use crate::util::ser::{FixedLengthReader, LengthRead, LengthReadableArgs, Readable, Writeable, Writer}; use crate::io::{self, Read, Write}; +use crate::ln::msgs::DecodeError; +use crate::util::ser::{ + FixedLengthReader, LengthRead, LengthReadableArgs, Readable, Writeable, Writer, +}; pub(crate) struct ChaChaReader<'a, R: io::Read> { pub chacha: &'a mut ChaCha20, @@ -58,7 +60,9 @@ impl LengthReadableArgs<[u8; 32]> for ChaChaPolyReadAdapter { // LengthRead must be used instead of std::io::Read because we need the total length to separate // out the tag at the end. fn read(r: &mut R, secret: [u8; 32]) -> Result { - if r.total_bytes() < 16 { return Err(DecodeError::InvalidValue) } + if r.total_bytes() < 16 { + return Err(DecodeError::InvalidValue); + } let mut chacha = ChaCha20Poly1305RFC::new(&secret, &[0; 12], &[]); let decrypted_len = r.total_bytes() - 16; @@ -70,14 +74,13 @@ impl LengthReadableArgs<[u8; 32]> for ChaChaPolyReadAdapter { let mut tag = [0 as u8; 16]; r.read_exact(&mut tag)?; if !chacha.finish_and_check_tag(&tag) { - return Err(DecodeError::InvalidValue) + return Err(DecodeError::InvalidValue); } Ok(Self { readable }) } } - /// Enables simultaneously reading and decrypting a ChaCha20Poly1305RFC stream from a std::io::Read. struct ChaChaPolyReader<'a, R: Read> { pub chacha: &'a mut ChaCha20Poly1305RFC, @@ -111,7 +114,9 @@ impl<'a, W: Writer> Writer for ChaChaPolyWriter<'a, W> { let mut src_idx = 0; while src_idx < src.len() { let mut write_buffer = [0; 8192]; - let bytes_written = (&mut write_buffer[..]).write(&src[src_idx..]).expect("In-memory writes can't fail"); + let bytes_written = (&mut write_buffer[..]) + .write(&src[src_idx..]) + .expect("In-memory writes can't fail"); self.chacha.encrypt_in_place(&mut write_buffer[..bytes_written]); self.write.write_all(&write_buffer[..bytes_written])?; src_idx += bytes_written; @@ -120,11 +125,10 @@ impl<'a, W: Writer> Writer for ChaChaPolyWriter<'a, W> { } } - #[cfg(test)] mod tests { - use crate::ln::msgs::DecodeError; use super::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter}; + use crate::ln::msgs::DecodeError; use crate::util::ser::{self, FixedLengthReader, LengthReadableArgs, Writeable}; // Used for for testing various lengths of serialization. @@ -155,34 +159,26 @@ mod tests { // Now deserialize the object back and make sure it matches the original. let mut rd = FixedLengthReader::new(encrypted_writeable, writeable_len); - let read_adapter = >::read(&mut rd, rho).unwrap(); + let read_adapter = + >::read(&mut rd, rho).unwrap(); assert_eq!($obj, read_adapter.readable); }; } // Try a big object that will require multiple write buffers. - let big_writeable = TestWriteable { - field1: vec![43], - field2: vec![44; 4192], - field3: vec![45; 4192 + 1], - }; + let big_writeable = + TestWriteable { field1: vec![43], field2: vec![44; 4192], field3: vec![45; 4192 + 1] }; check_object_read_write!(big_writeable); // Try a small object that fits into one write buffer. - let small_writeable = TestWriteable { - field1: vec![43], - field2: vec![44], - field3: vec![45], - }; + let small_writeable = + TestWriteable { field1: vec![43], field2: vec![44], field3: vec![45] }; check_object_read_write!(small_writeable); } fn do_chacha_stream_adapters_ser_macros() -> Result<(), DecodeError> { - let writeable = TestWriteable { - field1: vec![43], - field2: vec![44; 4192], - field3: vec![45; 4192 + 1], - }; + let writeable = + TestWriteable { field1: vec![43], field2: vec![44; 4192], field3: vec![45; 4192 + 1] }; // First, serialize the object into a TLV stream, encrypted with ChaCha20Poly1305. let rho = [42; 32]; diff --git a/lightning/src/crypto/utils.rs b/lightning/src/crypto/utils.rs index aab406157f8..cd4d9bfa6d5 100644 --- a/lightning/src/crypto/utils.rs +++ b/lightning/src/crypto/utils.rs @@ -1,7 +1,7 @@ -use bitcoin::hashes::{Hash, HashEngine}; use bitcoin::hashes::hmac::{Hmac, HmacEngine}; use bitcoin::hashes::sha256::Hash as Sha256; -use bitcoin::secp256k1::{Message, Secp256k1, SecretKey, ecdsa::Signature, Signing}; +use bitcoin::hashes::{Hash, HashEngine}; +use bitcoin::secp256k1::{ecdsa::Signature, Message, Secp256k1, SecretKey, Signing}; use crate::sign::EntropySource; @@ -43,14 +43,16 @@ macro_rules! hkdf_extract_expand { let k5 = Hmac::from_engine(hmac).to_byte_array(); (k1, k2, k3, k4, k5) - }} + }}; } pub fn hkdf_extract_expand_twice(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32]) { hkdf_extract_expand!(salt, ikm, 2) } -pub fn hkdf_extract_expand_5x(salt: &[u8], ikm: &[u8]) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32]) { +pub fn hkdf_extract_expand_5x( + salt: &[u8], ikm: &[u8], +) -> ([u8; 32], [u8; 32], [u8; 32], [u8; 32], [u8; 32]) { hkdf_extract_expand!(salt, ikm, 5) } @@ -66,8 +68,11 @@ pub fn sign(ctx: &Secp256k1, msg: &Message, sk: &SecretKey) -> Si #[inline] #[allow(unused_variables)] pub fn sign_with_aux_rand( - ctx: &Secp256k1, msg: &Message, sk: &SecretKey, entropy_source: &ES -) -> Signature where ES::Target: EntropySource { + ctx: &Secp256k1, msg: &Message, sk: &SecretKey, entropy_source: &ES, +) -> Signature +where + ES::Target: EntropySource, +{ #[cfg(feature = "grind_signatures")] let sig = loop { let sig = ctx.sign_ecdsa_with_noncedata(msg, sk, &entropy_source.get_secure_random_bytes()); diff --git a/lightning/src/events/mod.rs b/lightning/src/events/mod.rs index a7cf68dcc1c..fe52d08c9e1 100644 --- a/lightning/src/events/mod.rs +++ b/lightning/src/events/mod.rs @@ -543,12 +543,13 @@ pub enum PaymentFailureReason { /// /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment UserAbandoned, - /// We exhausted all of our retry attempts while trying to send the payment, or we - /// exhausted the [`Retry::Timeout`] if the user set one. If at any point a retry - /// attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will + #[cfg_attr(feature = "std", doc = "We exhausted all of our retry attempts while trying to send the payment, or we")] + #[cfg_attr(feature = "std", doc = "exhausted the [`Retry::Timeout`] if the user set one.")] + #[cfg_attr(not(feature = "std"), doc = "We exhausted all of our retry attempts while trying to send the payment.")] + /// If at any point a retry attempt failed while being forwarded along the path, an [`Event::PaymentPathFailed`] will /// have come before this. - /// - /// [`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout + #[cfg_attr(feature = "std", doc = "")] + #[cfg_attr(feature = "std", doc = "[`Retry::Timeout`]: crate::ln::channelmanager::Retry::Timeout")] RetriesExhausted, /// The payment expired while retrying, based on the provided /// [`PaymentParameters::expiry_time`]. diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 95953e6a033..106a8fdd677 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -28,7 +28,6 @@ //! //! * `std` //! * `grind_signatures` -//! * `no-std ` - exposes write trait implementations from the `core2` crate (at least one of `no-std` or `std` are required) //! * Skip logging of messages at levels below the given log level: //! * `max_level_off` //! * `max_level_error` @@ -53,9 +52,6 @@ #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] -#[cfg(not(any(feature = "std", feature = "no-std")))] -compile_error!("at least one of the `std` or `no-std` features must be enabled"); - #[cfg(all(fuzzing, test))] compile_error!("Tests will always fail with cfg=fuzzing"); diff --git a/lightning/src/ln/async_signer_tests.rs b/lightning/src/ln/async_signer_tests.rs index a8d15d8af06..f607431820e 100644 --- a/lightning/src/ln/async_signer_tests.rs +++ b/lightning/src/ln/async_signer_tests.rs @@ -42,10 +42,10 @@ fn test_async_commitment_signature_for_funding_created() { // nodes[0] --- open_channel --> nodes[1] let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); // nodes[0] <-- accept_channel --- nodes[1] - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); // nodes[0] --- funding_created --> nodes[1] // @@ -70,13 +70,13 @@ fn test_async_commitment_signature_for_funding_created() { nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors(&nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); // nodes[0] <-- funding_signed --- nodes[1] let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); } @@ -93,10 +93,10 @@ fn test_async_commitment_signature_for_funding_signed() { // nodes[0] --- open_channel --> nodes[1] let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); // nodes[0] <-- accept_channel --- nodes[1] - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); // nodes[0] --- funding_created --> nodes[1] let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); @@ -108,7 +108,7 @@ fn test_async_commitment_signature_for_funding_signed() { // Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should // *not* broadcast a `funding_signed`... nodes[1].disable_channel_signer_op(&nodes[0].node.get_our_node_id(), &temporary_channel_id, SignerOp::SignCounterpartyCommitment); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors(&nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -127,7 +127,7 @@ fn test_async_commitment_signature_for_funding_signed() { // nodes[0] <-- funding_signed --- nodes[1] let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); } @@ -168,14 +168,14 @@ fn do_test_async_commitment_signature_for_commitment_signed_revoke_and_ack(enabl assert_eq!(payment_event.node_id, dst.node.get_our_node_id()); assert_eq!(payment_event.msgs.len(), 1); - dst.node.handle_update_add_htlc(&src.node.get_our_node_id(), &payment_event.msgs[0]); + dst.node.handle_update_add_htlc(src.node.get_our_node_id(), &payment_event.msgs[0]); // Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a // `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`. dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::GetPerCommitmentPoint); dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::ReleaseCommitmentSecret); dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); - dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg); + dst.node.handle_commitment_signed(src.node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors(dst, 1); let mut enabled_signer_ops = HashSet::new(); @@ -218,7 +218,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); { let events = nodes[1].node.get_and_clear_pending_events(); @@ -236,7 +236,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() { // nodes[0] <-- accept_channel --- nodes[1] let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); assert_eq!(accept_channel.common_fields.minimum_depth, 0, "Expected minimum depth of 0"); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); // nodes[0] --- funding_created --> nodes[1] let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); @@ -248,7 +248,7 @@ fn test_async_commitment_signature_for_funding_signed_0conf() { // Now let's make node[1]'s signer be unavailable while handling the `funding_created`. It should // *not* broadcast a `funding_signed`... nodes[1].disable_channel_signer_op(&nodes[0].node.get_our_node_id(), &temporary_channel_id, SignerOp::SignCounterpartyCommitment); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors(&nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -279,24 +279,24 @@ fn test_async_commitment_signature_for_funding_signed_0conf() { (funding_signed, channel_ready) }; - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); check_added_monitors(&nodes[0], 1); let channel_ready_0 = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &channel_ready_1); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &channel_ready_1); expect_channel_ready_event(&nodes[0], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &channel_ready_0); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &channel_ready_0); expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id()); let channel_update_0 = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); let channel_update_1 = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &channel_update_1); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &channel_update_0); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &channel_update_1); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &channel_update_0); assert_eq!(nodes[0].node.list_usable_channels().len(), 1); assert_eq!(nodes[1].node.list_usable_channels().len(), 1); @@ -350,7 +350,7 @@ fn do_test_async_raa_peer_disconnect(test_case: UnblockSignerAcrossDisconnectCas assert_eq!(payment_event.node_id, dst.node.get_our_node_id()); assert_eq!(payment_event.msgs.len(), 1); - dst.node.handle_update_add_htlc(&src.node.get_our_node_id(), &payment_event.msgs[0]); + dst.node.handle_update_add_htlc(src.node.get_our_node_id(), &payment_event.msgs[0]); if test_case == UnblockSignerAcrossDisconnectCase::BeforeMonitorRestored { // Fail to persist the monitor update when handling the commitment_signed. @@ -360,23 +360,23 @@ fn do_test_async_raa_peer_disconnect(test_case: UnblockSignerAcrossDisconnectCas // Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a // `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`. dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, block_raa_signer_op); - dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg); + dst.node.handle_commitment_signed(src.node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors(dst, 1); let events = dst.node.get_and_clear_pending_msg_events(); assert!(events.is_empty(), "expected no message, got {}", events.len()); // Now disconnect and reconnect the peers. - src.node.peer_disconnected(&dst.node.get_our_node_id()); - dst.node.peer_disconnected(&src.node.get_our_node_id()); + src.node.peer_disconnected(dst.node.get_our_node_id()); + dst.node.peer_disconnected(src.node.get_our_node_id()); // do reestablish stuff - src.node.peer_connected(&dst.node.get_our_node_id(), &msgs::Init { + src.node.peer_connected(dst.node.get_our_node_id(), &msgs::Init { features: dst.node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(src, dst); assert_eq!(reestablish_1.len(), 1); - dst.node.peer_connected(&src.node.get_our_node_id(), &msgs::Init { + dst.node.peer_connected(src.node.get_our_node_id(), &msgs::Init { features: src.node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(dst, src); @@ -387,7 +387,7 @@ fn do_test_async_raa_peer_disconnect(test_case: UnblockSignerAcrossDisconnectCas dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, block_raa_signer_op); } - dst.node.handle_channel_reestablish(&src.node.get_our_node_id(), &reestablish_1[0]); + dst.node.handle_channel_reestablish(src.node.get_our_node_id(), &reestablish_1[0]); if test_case == UnblockSignerAcrossDisconnectCase::BeforeMonitorRestored { dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, block_raa_signer_op); @@ -474,7 +474,7 @@ fn do_test_async_commitment_signature_peer_disconnect(test_case: UnblockSignerAc assert_eq!(payment_event.node_id, dst.node.get_our_node_id()); assert_eq!(payment_event.msgs.len(), 1); - dst.node.handle_update_add_htlc(&src.node.get_our_node_id(), &payment_event.msgs[0]); + dst.node.handle_update_add_htlc(src.node.get_our_node_id(), &payment_event.msgs[0]); if test_case == UnblockSignerAcrossDisconnectCase::BeforeMonitorRestored { // Fail to persist the monitor update when handling the commitment_signed. @@ -484,7 +484,7 @@ fn do_test_async_commitment_signature_peer_disconnect(test_case: UnblockSignerAc // Mark dst's signer as unavailable and handle src's commitment_signed: while dst won't yet have a // `commitment_signed` of its own to offer, it should publish a `revoke_and_ack`. dst.disable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); - dst.node.handle_commitment_signed(&src.node.get_our_node_id(), &payment_event.commitment_msg); + dst.node.handle_commitment_signed(src.node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors(dst, 1); if test_case != UnblockSignerAcrossDisconnectCase::BeforeMonitorRestored { @@ -492,16 +492,16 @@ fn do_test_async_commitment_signature_peer_disconnect(test_case: UnblockSignerAc } // Now disconnect and reconnect the peers. - src.node.peer_disconnected(&dst.node.get_our_node_id()); - dst.node.peer_disconnected(&src.node.get_our_node_id()); + src.node.peer_disconnected(dst.node.get_our_node_id()); + dst.node.peer_disconnected(src.node.get_our_node_id()); // do reestablish stuff - src.node.peer_connected(&dst.node.get_our_node_id(), &msgs::Init { + src.node.peer_connected(dst.node.get_our_node_id(), &msgs::Init { features: dst.node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(src, dst); assert_eq!(reestablish_1.len(), 1); - dst.node.peer_connected(&src.node.get_our_node_id(), &msgs::Init { + dst.node.peer_connected(src.node.get_our_node_id(), &msgs::Init { features: src.node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(dst, src); @@ -512,7 +512,7 @@ fn do_test_async_commitment_signature_peer_disconnect(test_case: UnblockSignerAc dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); } - dst.node.handle_channel_reestablish(&src.node.get_our_node_id(), &reestablish_1[0]); + dst.node.handle_channel_reestablish(src.node.get_our_node_id(), &reestablish_1[0]); if test_case == UnblockSignerAcrossDisconnectCase::BeforeMonitorRestored { dst.enable_channel_signer_op(&src.node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); @@ -595,12 +595,12 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { assert_eq!(events_2.len(), 1); match events_2[0] { MessageSendEvent::UpdateHTLCs { node_id: _, updates: msgs::CommitmentUpdate { ref update_fulfill_htlcs, ref commitment_signed, .. } } => { - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); if monitor_update_failure { chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); } - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), commitment_signed); if monitor_update_failure { assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } else { @@ -614,15 +614,15 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { // Disconnect and reconnect the peers so that nodes[0] will // need to re-send the commitment update *and then* revoke_and_ack. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); @@ -632,7 +632,7 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { // and then revoke_and_ack. With commitment_signed disabled, since // our ordering is CS then RAA, we should make sure we don't send the RAA. nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_id, SignerOp::SignCounterpartyCommitment); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); assert!(as_resp.0.is_none()); assert!(as_resp.1.is_none()); @@ -657,7 +657,7 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { nodes[0].node.signer_unblocked(Some((nodes[1].node.get_our_node_id(), chan_id))); let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); let bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]); assert!(as_resp.0.is_none()); @@ -669,33 +669,33 @@ fn do_test_async_commitment_signature_ordering(monitor_update_failure: bool) { assert!(as_resp.3 == RAACommitmentOrder::CommitmentFirst); // Now that everything is restored, get the CS + RAA and handle them. - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().update_add_htlcs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().commitment_signed); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), as_resp.1.as_ref().unwrap()); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().update_add_htlcs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().commitment_signed); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), as_resp.1.as_ref().unwrap()); let (bs_revoke_and_ack, bs_second_commitment_signed) = get_revoke_commit_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 2); // The rest of this is boilerplate for resolving the previous state. - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); let as_commitment_signed = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_commitment_signed); let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_commitment_signed.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_commitment_signed.commitment_signed); let bs_second_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); @@ -854,11 +854,13 @@ fn test_async_holder_signatures_remote_commitment_anchors() { #[test] fn test_closing_signed() { - do_test_closing_signed(false); - do_test_closing_signed(true); + do_test_closing_signed(false, false); + do_test_closing_signed(true, false); + do_test_closing_signed(false, true); + do_test_closing_signed(true, true); } -fn do_test_closing_signed(extra_closing_signed: bool) { +fn do_test_closing_signed(extra_closing_signed: bool, reconnect: bool) { // Based off of `expect_channel_shutdown_state`. // Test that we can asynchronously sign closing transactions. let chanmon_cfgs = create_chanmon_cfgs(2); @@ -867,6 +869,9 @@ fn do_test_closing_signed(extra_closing_signed: bool) { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1); + // Avoid extra channel ready message upon reestablish later + send_payment(&nodes[0], &vec![&nodes[1]][..], 8_000_000); + expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::NotShuttingDown); nodes[0].node.close_channel(&chan_1.2, &nodes[1].node.get_our_node_id()).unwrap(); @@ -875,14 +880,14 @@ fn do_test_closing_signed(extra_closing_signed: bool) { expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NotShuttingDown); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::ShutdownInitiated); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); @@ -894,7 +899,7 @@ fn do_test_closing_signed(extra_closing_signed: bool) { let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); nodes[1].disable_channel_signer_op(&nodes[0].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert!(events.is_empty(), "Expected no events, got {:?}", events); @@ -904,7 +909,7 @@ fn do_test_closing_signed(extra_closing_signed: bool) { let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); nodes[0].disable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert!(events.is_empty(), "Expected no events, got {:?}", events); nodes[0].enable_channel_signer_op(&nodes[1].node.get_our_node_id(), &chan_1.2, SignerOp::SignClosingTransaction); @@ -914,7 +919,7 @@ fn do_test_closing_signed(extra_closing_signed: bool) { let mut node_1_closing_signed_2 = node_1_closing_signed.clone(); let holder_script = nodes[0].keys_manager.get_shutdown_scriptpubkey().unwrap(); let counterparty_script = nodes[1].keys_manager.get_shutdown_scriptpubkey().unwrap(); - let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.txid(), vout: 0 }; + let funding_outpoint = bitcoin::OutPoint { txid: chan_1.3.compute_txid(), vout: 0 }; let closing_tx_2 = ClosingTransaction::new(50000, 0, holder_script.into(), counterparty_script.into(), funding_outpoint); @@ -927,7 +932,7 @@ fn do_test_closing_signed(extra_closing_signed: bool) { node_1_closing_signed_2.signature = signature; node_1_closing_signed_2 }; - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed_2_bad); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed_2_bad); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -941,10 +946,46 @@ fn do_test_closing_signed(extra_closing_signed: bool) { }; } + if reconnect { + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + + *nodes[0].fee_estimator.sat_per_kw.lock().unwrap() *= 8; + *nodes[1].fee_estimator.sat_per_kw.lock().unwrap() *= 8; + + connect_nodes(&nodes[0], &nodes[1]); + let node_0_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); + let node_1_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &node_0_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &node_1_reestablish); + + let node_0_msgs = nodes[0].node.get_and_clear_pending_msg_events(); + assert_eq!(node_0_msgs.len(), 2); + let node_0_2nd_shutdown = match node_0_msgs[0] { + MessageSendEvent::SendShutdown { ref msg, .. } => { + msg.clone() + }, + _ => panic!(), + }; + let node_0_2nd_closing_signed = match node_0_msgs[1] { + MessageSendEvent::SendClosingSigned { ref msg, .. } => { + msg.clone() + }, + _ => panic!(), + }; + let node_1_2nd_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); + + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_2nd_shutdown); + assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_2nd_shutdown); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed); + let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); + } + nodes[0].node.signer_unblocked(None); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_closing_signed.is_none()); @@ -952,4 +993,5 @@ fn do_test_closing_signed(extra_closing_signed: bool) { assert!(nodes[1].node.list_channels().is_empty()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyInitiatedCooperativeClosure, [nodes[0].node.get_our_node_id()], 100000); + } diff --git a/lightning/src/ln/blinded_payment_tests.rs b/lightning/src/ln/blinded_payment_tests.rs index c19447efbd6..d099e439ae5 100644 --- a/lightning/src/ln/blinded_payment_tests.rs +++ b/lightning/src/ln/blinded_payment_tests.rs @@ -328,7 +328,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) { }, ForwardCheckFail::OutboundChannelCheck => { // The intro node will see that the next-hop peer is disconnected and fail the HTLC backwards. - nodes[$src_node_idx].node.peer_disconnected(&nodes[$target_node_idx].node.get_our_node_id()); + nodes[$src_node_idx].node.peer_disconnected(nodes[$target_node_idx].node.get_our_node_id()); } } } @@ -341,13 +341,13 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) { cause_error!(1, 2, update_add); } - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); check_added_monitors!(nodes[1], 0); do_commitment_signed_dance(&nodes[1], &nodes[0], &updates_0_1.commitment_signed, true, true); if intro_fails { let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -362,7 +362,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) { cause_error!(2, 3, update_add); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &updates_1_2.commitment_signed, true, true); @@ -374,11 +374,11 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) { // Ensure the intro node will properly blind the error if its downstream node failed to do so. update_malformed.sha256_of_onion = [1; 32]; update_malformed.failure_code = INVALID_ONION_BLINDING ^ 1; - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[1], &nodes[2], &updates.commitment_signed, true, false); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -409,7 +409,7 @@ fn failed_backwards_to_intro_node() { let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); let mut payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); do_commitment_signed_dance(&nodes[1], &nodes[0], &payment_event.commitment_msg, false, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -422,7 +422,7 @@ fn failed_backwards_to_intro_node() { // Ensure the final node fails to handle the HTLC. payment_event.msgs[0].onion_routing_packet.hop_data[0] ^= 1; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event.commitment_msg, true, true); nodes[2].node.process_pending_htlc_forwards(); @@ -436,11 +436,11 @@ fn failed_backwards_to_intro_node() { // Modify such the final hop does not correctly blind their error so we can ensure the intro node // converts it to the correct error. update_malformed.sha256_of_onion = [1; 32]; - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[1], &nodes[2], &updates.commitment_signed, true, false); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -490,7 +490,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck, let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); let mut payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); do_commitment_signed_dance(&nodes[1], &nodes[0], &payment_event.commitment_msg, false, false); @@ -500,7 +500,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck, ProcessPendingHTLCsCheck::FwdPeerDisconnected => { // Disconnect the next-hop peer so when we go to forward in process_pending_htlc_forwards, the // intro node will error backwards. - $curr_node.node.peer_disconnected(&$next_node.node.get_our_node_id()); + $curr_node.node.peer_disconnected($next_node.node.get_our_node_id()); expect_pending_htlcs_forwardable!($curr_node); expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!($curr_node, vec![HTLCDestination::NextHopChannel { node_id: Some($next_node.node.get_our_node_id()), channel_id: $failed_chan_id }]); @@ -533,7 +533,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck, if intro_fails { cause_error!(nodes[0], nodes[1], nodes[2], chan_id_1_2, chan_upd_1_2.short_channel_id); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); check_added_monitors!(nodes[1], 1); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); @@ -547,7 +547,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck, let mut updates_1_2 = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); let mut update_add = &mut updates_1_2.update_add_htlcs[0]; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &updates_1_2.commitment_signed, true, true); @@ -562,11 +562,11 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck, // Ensure the intro node will properly blind the error if its downstream node failed to do so. update_malformed.sha256_of_onion = [1; 32]; update_malformed.failure_code = INVALID_ONION_BLINDING ^ 1; - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[1], &nodes[2], &updates.commitment_signed, true, false); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -607,7 +607,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &payment_event.commitment_msg, false, true); let events = nodes[1].node.get_and_clear_pending_events(); @@ -632,7 +632,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) { check_added_monitors!(&nodes[1], 1); assert!(update_fail.update_fail_htlcs.len() == 1); let fail_msg = update_fail.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_fail.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -652,7 +652,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], &payment_event.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[2]); @@ -747,7 +747,7 @@ fn three_hop_blinded_path_fail() { let update_malformed = &updates_3_2.update_fail_malformed_htlcs[0]; assert_eq!(update_malformed.sha256_of_onion, [0; 32]); assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING); - nodes[2].node.handle_update_fail_malformed_htlc(&nodes[3].node.get_our_node_id(), update_malformed); + nodes[2].node.handle_update_fail_malformed_htlc(nodes[3].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[2], &nodes[3], &updates_3_2.commitment_signed, true, false); let updates_2_1 = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -755,12 +755,12 @@ fn three_hop_blinded_path_fail() { let update_malformed = &updates_2_1.update_fail_malformed_htlcs[0]; assert_eq!(update_malformed.sha256_of_onion, [0; 32]); assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING); - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[1], &nodes[2], &updates_2_1.commitment_signed, true, false); let updates_1_0 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates_1_0.update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_1_0.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates_1_0.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates_1_0.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -860,7 +860,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); SendEvent::from_event(ev) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event_0_1.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event_0_1.msgs[0]); check_added_monitors!(nodes[1], 0); do_commitment_signed_dance(&nodes[1], &nodes[0], &payment_event_0_1.commitment_msg, false, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -875,7 +875,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { match check { ReceiveCheckFail::RecipientFail => { - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); expect_pending_htlcs_forwardable!(nodes[2]); @@ -911,33 +911,33 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { vec![onion_payloads.pop().unwrap()], vec![onion_keys.pop().unwrap()], [0; 32], &payment_hash ).unwrap(); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), update_add); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), update_add); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); }, ReceiveCheckFail::ReceiveRequirements => { let update_add = &mut payment_event_1_2.msgs[0]; update_add.amount_msat -= 1; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), update_add); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), update_add); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); }, ReceiveCheckFail::ChannelCheck => { nodes[2].node.close_channel(&chan_id_1_2, &nodes[1].node.get_our_node_id()).unwrap(); let node_2_shutdown = get_event_msg!(nodes[2], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[2].node.get_our_node_id(), &node_2_shutdown); + nodes[1].node.handle_shutdown(nodes[2].node.get_our_node_id(), &node_2_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &payment_event_1_2.commitment_msg); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &payment_event_1_2.commitment_msg); check_added_monitors!(nodes[2], 1); - nodes[2].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[2].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); commitment_signed_dance!(nodes[2], nodes[1], (), false, true, false, false); }, ReceiveCheckFail::ProcessPendingHTLCsCheck => { assert_eq!(payment_event_1_2.msgs[0].cltv_expiry, nodes[0].best_block_info().1 + 1 + excess_final_cltv_delta_opt.unwrap() as u32 + TEST_FINAL_CLTV); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); expect_pending_htlcs_forwardable!(nodes[2]); @@ -946,7 +946,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { check_added_monitors!(nodes[2], 1); }, ReceiveCheckFail::PaymentConstraints => { - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_1_2.msgs[0]); check_added_monitors!(nodes[2], 0); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true); } @@ -957,7 +957,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { let update_malformed = &updates_2_1.update_fail_malformed_htlcs[0]; assert_eq!(update_malformed.sha256_of_onion, [0; 32]); assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING); - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&nodes[1], &nodes[2], &updates_2_1.commitment_signed, true, false); let updates_1_0 = if check == ReceiveCheckFail::ChannelCheck { @@ -975,7 +975,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) { }).unwrap() } else { get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()) }; assert_eq!(updates_1_0.update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_1_0.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates_1_0.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates_1_0.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); @@ -1040,12 +1040,12 @@ fn blinded_path_retries() { let update_malformed = &updates.update_fail_malformed_htlcs[0]; assert_eq!(update_malformed.sha256_of_onion, [0; 32]); assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING); - $intro_node.node.handle_update_fail_malformed_htlc(&nodes[3].node.get_our_node_id(), update_malformed); + $intro_node.node.handle_update_fail_malformed_htlc(nodes[3].node.get_our_node_id(), update_malformed); do_commitment_signed_dance(&$intro_node, &nodes[3], &updates.commitment_signed, true, false); let updates = get_htlc_update_msgs!($intro_node, nodes[0].node.get_our_node_id()); assert_eq!(updates.update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&$intro_node.node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc($intro_node.node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &$intro_node, &updates.commitment_signed, false, false); let mut events = nodes[0].node.get_and_clear_pending_events(); @@ -1146,11 +1146,11 @@ fn min_htlc() { let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); SendEvent::from_event(ev) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event_0_1.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event_0_1.msgs[0]); check_added_monitors!(nodes[1], 0); do_commitment_signed_dance(&nodes[1], &nodes[0], &payment_event_0_1.commitment_msg, true, true); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &updates.commitment_signed, false, false); expect_payment_failed_conditions(&nodes[0], payment_hash, false, PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32])); diff --git a/lightning/src/ln/bolt11_payment.rs b/lightning/src/ln/bolt11_payment.rs index d0655968a60..13840dc05d7 100644 --- a/lightning/src/ln/bolt11_payment.rs +++ b/lightning/src/ln/bolt11_payment.rs @@ -199,7 +199,7 @@ mod tests { .unwrap(); check_added_monitors(&nodes[0], 1); let send_event = SendEvent::from_node(&nodes[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index c4bfac1dd97..5b276b1c2ae 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -93,7 +93,7 @@ fn test_monitor_and_persister_update_fail() { let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); { let mut node_0_per_peer_lock; @@ -144,8 +144,8 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { assert_eq!(nodes[0].node.list_channels().len(), 1); if disconnect { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); reconnect_args.send_channel_ready = (true, true); reconnect_nodes(reconnect_args); @@ -160,7 +160,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { assert_eq!(events_2.len(), 1); let payment_event = SendEvent::from_event(events_2.pop().unwrap()); assert_eq!(payment_event.node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -201,8 +201,8 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) { assert_eq!(nodes[0].node.list_channels().len(), 1); if disconnect { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); } @@ -285,7 +285,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { assert!(update_fee.is_none()); if (disconnect_count & 16) == 0 { - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); let events_3 = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events_3.len(), 1); match events_3[0] { @@ -296,7 +296,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { _ => panic!("Unexpected event"), } - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), commitment_signed); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } @@ -307,8 +307,8 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { }; if disconnect_count & !disconnect_flags > 0 { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); } // Now fix monitor updating... @@ -318,23 +318,23 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { check_added_monitors!(nodes[0], 0); macro_rules! disconnect_reconnect_peers { () => { { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 1); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); let bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]); assert!(as_resp.0.is_none()); @@ -347,21 +347,21 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { assert!(nodes[0].node.get_and_clear_pending_events().is_empty()); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 1); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); check_added_monitors!(nodes[0], 0); let mut as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); check_added_monitors!(nodes[1], 0); let mut bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]); @@ -385,7 +385,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { assert!(as_resp.1.is_none()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_resp.2.as_ref().unwrap().update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_resp.2.as_ref().unwrap().update_fulfill_htlcs[0]); let events_3 = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events_3.len(), 1); match events_3[0] { @@ -396,7 +396,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { _ => panic!("Unexpected event"), } - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_resp.2.as_ref().unwrap().commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_resp.2.as_ref().unwrap().commitment_signed); let as_resp_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); @@ -431,8 +431,8 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { assert_eq!(payment_event.node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); let bs_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // nodes[1] is awaiting an RAA from nodes[0] still so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); @@ -451,7 +451,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { let bs_second_commitment_update; macro_rules! handle_bs_raa { () => { - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); as_commitment_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert!(as_commitment_update.update_add_htlcs.is_empty()); assert!(as_commitment_update.update_fulfill_htlcs.is_empty()); @@ -462,7 +462,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { } } macro_rules! handle_initial_raa { () => { - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &initial_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &initial_revoke_and_ack); bs_second_commitment_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(bs_second_commitment_update.update_add_htlcs.is_empty()); assert!(bs_second_commitment_update.update_fulfill_htlcs.is_empty()); @@ -526,21 +526,21 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { } } - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_commitment_update.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_commitment_update.commitment_signed); let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_commitment_update.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_commitment_update.commitment_signed); let bs_second_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); @@ -613,10 +613,10 @@ fn test_monitor_update_fail_cs() { } let send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event.commitment_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &send_event.commitment_msg); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -631,7 +631,7 @@ fn test_monitor_update_fail_cs() { match responses[0] { MessageSendEvent::SendRevokeAndACK { ref msg, ref node_id } => { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &msg); check_added_monitors!(nodes[0], 1); }, _ => panic!("Unexpected event"), @@ -646,7 +646,7 @@ fn test_monitor_update_fail_cs() { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &updates.commitment_signed); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -660,7 +660,7 @@ fn test_monitor_update_fail_cs() { check_added_monitors!(nodes[0], 0); let final_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &final_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &final_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); @@ -706,11 +706,11 @@ fn test_monitor_update_fail_no_rebroadcast() { } let send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); let bs_raa = commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false, true, false, true); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &bs_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &bs_raa); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); @@ -762,20 +762,20 @@ fn test_monitor_update_raa_while_paused() { } let send_event_2 = SendEvent::from_event(nodes[1].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event_1.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event_1.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event_1.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &send_event_1.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event_2.msgs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_2.commitment_msg); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_event_2.msgs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &send_event_2.commitment_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); @@ -784,24 +784,24 @@ fn test_monitor_update_raa_while_paused() { check_added_monitors!(nodes[0], 0); let as_update_raa = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_update_raa.0); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_update_raa.0); check_added_monitors!(nodes[1], 1); let bs_cs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_update_raa.1); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_update_raa.1); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs.commitment_signed); check_added_monitors!(nodes[0], 1); let as_second_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); expect_pending_htlcs_forwardable!(nodes[0]); expect_payment_claimable!(nodes[0], our_payment_hash_2, our_payment_secret_2, 1000000); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], our_payment_hash_1, our_payment_secret_1, 1000000); @@ -836,7 +836,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); let bs_revoke_and_ack = commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false, true, false, true); check_added_monitors!(nodes[0], 0); @@ -851,7 +851,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { } let mut send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -860,7 +860,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { // Now fail monitor updating. chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -877,7 +877,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); // We succeed in updating the monitor for the first channel send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false, true); check_added_monitors!(nodes[1], 0); @@ -895,8 +895,8 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { check_added_monitors!(nodes[2], 1); send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &send_event.commitment_msg); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); (Some(payment_preimage_4), Some(payment_hash_4)) @@ -951,17 +951,17 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { // Now deliver the new messages... - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &messages_a.0); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &messages_a.0); commitment_signed_dance!(nodes[0], nodes[1], messages_a.1, false); expect_payment_failed!(nodes[0], payment_hash_1, true); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event_b.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_event_b.msgs[0]); let as_cs; if test_ignore_second_cs { - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_b.commitment_msg); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &send_event_b.commitment_msg); check_added_monitors!(nodes[2], 1); let bs_revoke_and_ack = get_event_msg!(nodes[2], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa.unwrap()); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa.unwrap()); check_added_monitors!(nodes[2], 1); let bs_cs = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); assert!(bs_cs.update_add_htlcs.is_empty()); @@ -970,14 +970,14 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { assert!(bs_cs.update_fulfill_htlcs.is_empty()); assert!(bs_cs.update_fee.is_none()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors!(nodes[1], 1); as_cs = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &bs_cs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &bs_cs.commitment_signed); check_added_monitors!(nodes[1], 1); } else { - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_b.commitment_msg); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &send_event_b.commitment_msg); check_added_monitors!(nodes[2], 1); let bs_revoke_and_commit = nodes[2].node.get_and_clear_pending_msg_events(); @@ -986,7 +986,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { match bs_revoke_and_commit[0] { MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => { assert_eq!(*node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &msg); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &msg); check_added_monitors!(nodes[1], 1); }, _ => panic!("Unexpected event"), @@ -1002,7 +1002,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fulfill_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[1], 1); }, _ => panic!("Unexpected event"), @@ -1017,24 +1017,24 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { let as_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &as_cs.update_add_htlcs[0]); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &as_cs.commitment_signed); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &as_cs.update_add_htlcs[0]); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &as_cs.commitment_signed); check_added_monitors!(nodes[2], 1); let bs_second_raa = get_event_msg!(nodes[2], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[2], 1); let bs_second_cs = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &bs_second_cs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &bs_second_cs.commitment_signed); check_added_monitors!(nodes[1], 1); let as_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_second_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[2], 1); assert!(nodes[2].node.get_and_clear_pending_msg_events().is_empty()); @@ -1058,7 +1058,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) { send_event = SendEvent::from_node(&nodes[1]); assert_eq!(send_event.node_id, nodes[0].node.get_our_node_id()); assert_eq!(send_event.msgs.len(), 1); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event.msgs[0]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[0], nodes[1], send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[0]); @@ -1095,8 +1095,8 @@ fn test_monitor_update_fail_reestablish() { let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); nodes[2].node.claim_funds(payment_preimage); check_added_monitors!(nodes[2], 1); @@ -1108,26 +1108,26 @@ fn test_monitor_update_fail_reestablish() { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let as_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reestablish); assert_eq!( get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()) .contents.channel_flags & 2, 0); // The "disabled" bit should be unset as we just reconnected @@ -1135,25 +1135,25 @@ fn test_monitor_update_fail_reestablish() { nodes[1].node.get_and_clear_pending_msg_events(); // Free the holding cell check_added_monitors!(nodes[1], 1); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); assert_eq!(get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(), as_reestablish); assert_eq!(get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(), bs_reestablish); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); assert_eq!( get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()) .contents.channel_flags & 2, 0); // The "disabled" bit should be unset as we just reconnected - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reestablish); check_added_monitors!(nodes[1], 0); assert_eq!( get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()) @@ -1170,7 +1170,7 @@ fn test_monitor_update_fail_reestablish() { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false); expect_payment_sent!(nodes[0], payment_preimage); } @@ -1208,18 +1208,18 @@ fn raa_no_response_awaiting_raa_state() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_responses.0); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_responses.0); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_responses.1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_responses.1); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); @@ -1228,13 +1228,13 @@ fn raa_no_response_awaiting_raa_state() { // then restore channel monitor updates. chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); @@ -1255,36 +1255,36 @@ fn raa_no_response_awaiting_raa_state() { check_added_monitors!(nodes[0], 0); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_responses.0); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_responses.0); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_responses.1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_responses.1); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // Finally deliver the RAA to nodes[1] which results in a CS response to the last update - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], payment_hash_2, payment_secret_2, 1000000); let bs_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_update.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_update.commitment_signed); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], payment_hash_3, payment_secret_3, 1000000); @@ -1311,31 +1311,31 @@ fn claim_while_disconnected_monitor_update_fail() { // Forward a payment for B to claim let (payment_preimage_1, payment_hash_1, ..) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); nodes[1].node.claim_funds(payment_preimage_1); check_added_monitors!(nodes[1], 1); expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let as_reconnect = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); let bs_reconnect = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reconnect); let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); // Now deliver a's reestablish, freeing the claim from the holding cell, but fail the monitor // update. chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reconnect); let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -1350,8 +1350,8 @@ fn claim_while_disconnected_monitor_update_fail() { } let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_updates.commitment_signed); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); // Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC @@ -1370,13 +1370,13 @@ fn claim_while_disconnected_monitor_update_fail() { match bs_msgs[0] { MessageSendEvent::UpdateHTLCs { ref node_id, ref updates } => { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); }, _ => panic!("Unexpected event"), @@ -1385,7 +1385,7 @@ fn claim_while_disconnected_monitor_update_fail() { match bs_msgs[1] { MessageSendEvent::SendRevokeAndACK { ref node_id, ref msg } => { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), msg); check_added_monitors!(nodes[0], 1); }, _ => panic!("Unexpected event"), @@ -1394,20 +1394,20 @@ fn claim_while_disconnected_monitor_update_fail() { let as_commitment = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let bs_commitment = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_commitment.commitment_signed); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_commitment.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_commitment.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], payment_hash_2, payment_secret_2, 1000000); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); @@ -1449,29 +1449,29 @@ fn monitor_failed_no_reestablish_response() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); // Now disconnect and immediately reconnect, delivering the channel_reestablish while nodes[1] // is still failing to update monitors. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let as_reconnect = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); let bs_reconnect = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reconnect); let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reconnect); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reconnect); let _as_channel_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); @@ -1480,13 +1480,13 @@ fn monitor_failed_no_reestablish_response() { check_added_monitors!(nodes[1], 0); let bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_responses.0); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_responses.0); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_responses.1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_responses.1); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1526,14 +1526,14 @@ fn first_message_on_recv_ordering() { assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); assert_eq!(payment_event.node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_responses.0); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_responses.0); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_responses.1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_responses.1); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); @@ -1555,15 +1555,15 @@ fn first_message_on_recv_ordering() { // Deliver the final RAA for the first payment, which does not require a response. RAAs // generally require a commitment_signed, so the fact that we're expecting an opposite response // to the next message also tests resetting the delivery order. - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); // Now deliver the update_add_htlc/commitment_signed for the second payment, which does need an // RAA/CS response, which should be generated when we call channel_monitor_update (with the // appropriate HTLC acceptance). - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -1576,13 +1576,13 @@ fn first_message_on_recv_ordering() { expect_payment_claimable!(nodes[1], payment_hash_1, payment_secret_1, 1000000); let bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_responses.0); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_responses.0); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_responses.1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_responses.1); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1638,7 +1638,7 @@ fn test_monitor_update_fail_claim() { let mut events = nodes[2].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 0); commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false, true); @@ -1652,7 +1652,7 @@ fn test_monitor_update_fail_claim() { let mut events = nodes[2].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 0); commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false, true); @@ -1665,7 +1665,7 @@ fn test_monitor_update_fail_claim() { check_added_monitors!(nodes[1], 0); let bs_fulfill_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_fulfill_update.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_fulfill_update.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_fulfill_update.commitment_signed, false); expect_payment_sent!(nodes[0], payment_preimage_1); @@ -1673,8 +1673,8 @@ fn test_monitor_update_fail_claim() { nodes[1].node.process_pending_htlc_forwards(); check_added_monitors!(nodes[1], 1); let bs_forward_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[0]); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[1]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[0]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[1]); commitment_signed_dance!(nodes[0], nodes[1], bs_forward_update.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[0]); @@ -1737,7 +1737,7 @@ fn test_monitor_update_on_pending_forwards() { check_added_monitors!(nodes[2], 1); let cs_fail_update = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &cs_fail_update.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &cs_fail_update.update_fail_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[2], cs_fail_update.commitment_signed, true, true); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -1751,7 +1751,7 @@ fn test_monitor_update_on_pending_forwards() { let mut events = nodes[2].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); @@ -1764,8 +1764,8 @@ fn test_monitor_update_on_pending_forwards() { check_added_monitors!(nodes[1], 0); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_add_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false, true); let events = nodes[0].node.get_and_clear_pending_events(); @@ -1816,7 +1816,7 @@ fn monitor_update_claim_fail_no_response() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); let as_raa = commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true, false, true); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); @@ -1832,13 +1832,13 @@ fn monitor_update_claim_fail_no_response() { check_added_monitors!(nodes[1], 0); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], payment_hash_2, payment_secret_2, 1000000); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false); expect_payment_sent!(nodes[0], payment_preimage_1); @@ -1856,8 +1856,8 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43, None, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43); @@ -1867,11 +1867,11 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); let channel_id = ChannelId::v1_from_funding_outpoint(OutPoint { txid: funding_created_msg.funding_txid, index: funding_created_msg.funding_output_index }); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors!(nodes[1], 1); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[0].node.get_and_clear_pending_events().is_empty()); @@ -1888,7 +1888,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: if confirm_a_first { confirm_transaction(&nodes[0], &funding_tx); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); } else { @@ -1898,8 +1898,8 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: } // Make sure nodes[1] isn't stupid enough to re-send the ChannelReady on reconnect - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); reconnect_args.send_channel_ready.1 = confirm_a_first; reconnect_nodes(reconnect_args); @@ -1916,7 +1916,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: } if !confirm_a_first && !restore_b_before_lock { confirm_transaction(&nodes[0], &funding_tx); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); } @@ -1931,7 +1931,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: let (channel_ready, channel_id) = create_chan_between_nodes_with_value_confirm_second(&nodes[0], &nodes[1]); (channel_id, create_chan_between_nodes_with_value_b(&nodes[1], &nodes[0], &channel_ready)) } else { - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id())); confirm_transaction(&nodes[0], &funding_tx); let (channel_ready, channel_id) = create_chan_between_nodes_with_value_confirm_second(&nodes[1], &nodes[0]); (channel_id, create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready)) @@ -1945,10 +1945,11 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf: let (channel_ready, channel_id) = create_chan_between_nodes_with_value_confirm_second(&nodes[0], &nodes[1]); (channel_id, create_chan_between_nodes_with_value_b(&nodes[1], &nodes[0], &channel_ready)) }; - for node in nodes.iter() { - assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); - node.gossip_sync.handle_channel_update(&as_update).unwrap(); - node.gossip_sync.handle_channel_update(&bs_update).unwrap(); + for (i, node) in nodes.iter().enumerate() { + let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id(); + assert!(node.gossip_sync.handle_channel_announcement(Some(counterparty_node_id), &announcement).unwrap()); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &as_update).unwrap(); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &bs_update).unwrap(); } if !restore_b_before_lock { @@ -2070,25 +2071,25 @@ fn test_pending_update_fee_ack_on_reconnect() { let as_update_fee_msgs = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert!(as_update_fee_msgs.update_fee.is_some()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), as_update_fee_msgs.update_fee.as_ref().unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_update_fee_msgs.commitment_signed); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), as_update_fee_msgs.update_fee.as_ref().unwrap()); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_update_fee_msgs.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_first_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // bs_first_raa is not delivered until it is re-generated after reconnect - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let as_connect_msg = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_connect_msg = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_connect_msg); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_connect_msg); let bs_resend_msgs = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(bs_resend_msgs.len(), 3); if let MessageSendEvent::UpdateHTLCs { ref updates, .. } = bs_resend_msgs[0] { @@ -2099,28 +2100,28 @@ fn test_pending_update_fee_ack_on_reconnect() { } else { panic!(); } if let MessageSendEvent::SendChannelUpdate { .. } = bs_resend_msgs[2] { } else { panic!(); } - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_connect_msg); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_connect_msg); get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_initial_send_msgs.update_add_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_initial_send_msgs.commitment_signed); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_initial_send_msgs.update_add_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_initial_send_msgs.commitment_signed); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); let bs_second_cs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()).commitment_signed; - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()).commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()).commitment_signed); check_added_monitors!(nodes[1], 1); let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_cs); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_third_raa); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[0]); @@ -2157,7 +2158,7 @@ fn test_fail_htlc_on_broadcast_after_claim() { expect_payment_claimed!(nodes[2], payment_hash, 2000); let cs_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); @@ -2169,7 +2170,7 @@ fn test_fail_htlc_on_broadcast_after_claim() { check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_id_2 }]); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, true, true); expect_payment_path_successful!(nodes[0]); @@ -2196,7 +2197,7 @@ fn do_update_fee_resend_test(deliver_update: bool, parallel_updates: bool) { let update_msgs = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert!(update_msgs.update_fee.is_some()); if deliver_update { - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msgs.update_fee.as_ref().unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msgs.update_fee.as_ref().unwrap()); } if parallel_updates { @@ -2208,59 +2209,59 @@ fn do_update_fee_resend_test(deliver_update: bool, parallel_updates: bool) { assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let as_connect_msg = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_connect_msg = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_connect_msg); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_connect_msg); get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_connect_msg); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_connect_msg); let mut as_reconnect_msgs = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(as_reconnect_msgs.len(), 2); if let MessageSendEvent::SendChannelUpdate { .. } = as_reconnect_msgs.pop().unwrap() {} else { panic!(); } let update_msgs = if let MessageSendEvent::UpdateHTLCs { updates, .. } = as_reconnect_msgs.pop().unwrap() { updates } else { panic!(); }; assert!(update_msgs.update_fee.is_some()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msgs.update_fee.as_ref().unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msgs.update_fee.as_ref().unwrap()); if parallel_updates { - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &update_msgs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &update_msgs.commitment_signed); check_added_monitors!(nodes[1], 1); let (bs_first_raa, bs_first_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); check_added_monitors!(nodes[0], 1); let as_second_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_first_cs); check_added_monitors!(nodes[0], 1); let as_first_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), as_second_update.update_fee.as_ref().unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_update.commitment_signed); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), as_second_update.update_fee.as_ref().unwrap()); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_second_update.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); let bs_second_cs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_cs.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_cs.commitment_signed); check_added_monitors!(nodes[0], 1); let as_second_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); } else { commitment_signed_dance!(nodes[1], nodes[0], update_msgs.commitment_signed, false); @@ -2331,13 +2332,13 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) { nodes[0].node.claim_funds(payment_preimage_0); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &send.commitment_msg); check_added_monitors!(nodes[1], 1); let (raa, cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa); check_added_monitors!(nodes[0], 1); if disconnect { @@ -2349,27 +2350,27 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) { persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); } else { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); } - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Now reconnect the two - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 1); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); let resp_1 = handle_chan_reestablish_msgs!(nodes[1], nodes[0]); check_added_monitors!(nodes[1], 0); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); let resp_0 = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); assert!(resp_0.0.is_none()); @@ -2412,7 +2413,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) { assert_eq!(events.len(), 1); // Deliver the pending in-flight CS - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &cs); check_added_monitors!(nodes[0], 1); let commitment_msg = match events.pop().unwrap() { @@ -2422,20 +2423,20 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[0].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[0].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[1], payment_preimage_0, None, false, false); assert_eq!(updates.update_add_htlcs.len(), 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); updates.commitment_signed }, _ => panic!("Unexpected event type!"), }; - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commitment_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commitment_msg); check_added_monitors!(nodes[1], 1); let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); expect_pending_htlcs_forwardable!(nodes[1]); expect_payment_claimable!(nodes[1], payment_hash_1, payment_secret_1, 100000); check_added_monitors!(nodes[1], 1); @@ -2499,14 +2500,14 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f check_added_monitors!(nodes[0], 1); let send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &send_event.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_raa, bs_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs); check_added_monitors!(nodes[0], 1); as_raa = Some(get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); @@ -2532,7 +2533,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f // Check that the message we're about to deliver matches the one generated: assert_eq!(fulfill_msg, cs_updates.update_fulfill_htlcs[0]); } - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &fulfill_msg); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &fulfill_msg); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); check_added_monitors!(nodes[1], 1); @@ -2540,7 +2541,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f if htlc_status != HTLCStatusAtDupClaim::HoldingCell { bs_updates = Some(get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id())); assert_eq!(bs_updates.as_ref().unwrap().update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); if htlc_status == HTLCStatusAtDupClaim::Cleared { commitment_signed_dance!(nodes[0], nodes[1], &bs_updates.as_ref().unwrap().commitment_signed, false); @@ -2550,8 +2551,8 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); } - nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); if second_fails { let mut reconnect_args = ReconnectArgs::new(&nodes[1], &nodes[2]); @@ -2565,13 +2566,13 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f } if htlc_status == HTLCStatusAtDupClaim::HoldingCell { - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa.unwrap()); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa.unwrap()); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable_ignore!(nodes[1]); // We finally receive the second payment, but don't claim it bs_updates = Some(get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id())); assert_eq!(bs_updates.as_ref().unwrap().update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.as_ref().unwrap().update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); } if htlc_status != HTLCStatusAtDupClaim::Cleared { @@ -2608,10 +2609,10 @@ fn test_temporary_error_during_shutdown() { chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); nodes[0].node.close_channel(&channel_id, &nodes[1].node.get_our_node_id()).unwrap(); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id())); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -2621,7 +2622,7 @@ fn test_temporary_error_during_shutdown() { let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone(); nodes[0].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id())); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -2629,11 +2630,11 @@ fn test_temporary_error_during_shutdown() { let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone(); nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id())); let (_, closing_signed_a) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); let txn_a = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &closing_signed_a.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &closing_signed_a.unwrap()); let (_, none_b) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(none_b.is_none()); let txn_b = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); @@ -2707,18 +2708,18 @@ fn double_temp_error() { } }; assert_eq!(node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_1); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_1); check_added_monitors!(nodes[0], 0); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed_b1); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed_b1); check_added_monitors!(nodes[0], 1); nodes[0].node.process_pending_htlc_forwards(); let (raa_a1, commitment_signed_a1) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[1], 0); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa_a1); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa_a1); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commitment_signed_a1); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commitment_signed_a1); check_added_monitors!(nodes[1], 1); // Complete the second HTLC. @@ -2745,11 +2746,11 @@ fn double_temp_error() { _ => panic!("Unexpected event"), }) }; - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa_b2); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa_b2); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_2); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_2); check_added_monitors!(nodes[0], 0); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed_b2, false); @@ -2776,7 +2777,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43, None, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); let events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -2791,7 +2792,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { _ => panic!("Unexpected event"), }; - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43); @@ -2799,7 +2800,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { check_added_monitors!(nodes[0], 0); let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); @@ -2809,7 +2810,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { MessageSendEvent::SendFundingSigned { msg, .. } => { chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &msg); check_added_monitors!(nodes[0], 1); } _ => panic!("Unexpected event"), @@ -2817,7 +2818,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) { if use_0conf { match &bs_signed_locked[1] { MessageSendEvent::SendChannelReady { msg, .. } => { - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &msg); } _ => panic!("Unexpected event"), } @@ -2867,7 +2868,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 43, None, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); let events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -2882,7 +2883,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo _ => panic!("Unexpected event"), }; - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43); @@ -2891,7 +2892,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors!(nodes[1], 1); // nodes[1] happily sends its funding_signed even though its awaiting the persistence of the @@ -2899,7 +2900,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo // transaction is confirmed. let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); @@ -2910,7 +2911,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo } if use_0conf || lock_commitment { let as_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_ready); } assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -2962,7 +2963,7 @@ fn test_blocked_chan_preimage_release() { expect_payment_claimed!(nodes[2], payment_hash_1, 1_000_000); let cs_htlc_fulfill_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_htlc_fulfill_updates.update_fulfill_htlcs[0]); do_commitment_signed_dance(&nodes[1], &nodes[2], &cs_htlc_fulfill_updates.commitment_signed, false, false); check_added_monitors(&nodes[1], 0); @@ -2974,7 +2975,7 @@ fn test_blocked_chan_preimage_release() { expect_payment_claimed!(nodes[0], payment_hash_2, 1_000_000); let as_htlc_fulfill_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.update_fulfill_htlcs[0]); check_added_monitors(&nodes[1], 1); // We generate only a preimage monitor update assert!(get_monitor!(nodes[1], chan_id_2).get_stored_preimages().contains_key(&payment_hash_2)); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -2982,12 +2983,12 @@ fn test_blocked_chan_preimage_release() { // Finish the CS dance between nodes[0] and nodes[1]. Note that until the event handling, the // update_fulfill_htlc + CS is held, even though the preimage is already on disk for the // channel. - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_htlc_fulfill_updates.commitment_signed); check_added_monitors(&nodes[1], 1); let (a, raa) = do_main_commitment_signed_dance(&nodes[1], &nodes[0], false); assert!(a.is_none()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa); check_added_monitors(&nodes[1], 0); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -3005,7 +3006,7 @@ fn test_blocked_chan_preimage_release() { let bs_htlc_fulfill_updates = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); check_added_monitors(&nodes[1], 1); - nodes[2].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[2].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_htlc_fulfill_updates.update_fulfill_htlcs[0]); do_commitment_signed_dance(&nodes[2], &nodes[1], &bs_htlc_fulfill_updates.commitment_signed, false, false); expect_payment_sent(&nodes[2], payment_preimage_2, None, true, true); } @@ -3049,7 +3050,7 @@ fn do_test_inverted_mon_completion_order(with_latest_manager: bool, complete_bc_ chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); let cs_updates = get_htlc_update_msgs(&nodes[2], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); // B generates a new monitor update for the A <-> B channel, but doesn't send the new messages // for it since the monitor update is marked in-progress. @@ -3059,20 +3060,20 @@ fn do_test_inverted_mon_completion_order(with_latest_manager: bool, complete_bc_ // Now step the Commitment Signed Dance between B and C forward a bit (or fully), ensuring we // won't get the preimage when the nodes reconnect and we have to get it from the // ChannelMonitor. - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); check_added_monitors(&nodes[1], 1); if complete_bc_commitment_dance { let (bs_revoke_and_ack, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors(&nodes[2], 1); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment_signed); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_commitment_signed); check_added_monitors(&nodes[2], 1); let cs_raa = get_event_msg!(nodes[2], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // At this point node B still hasn't persisted the `ChannelMonitorUpdate` with the // preimage in the A <-> B channel, which will prevent it from persisting the // `ChannelMonitorUpdate` for the B<->C channel here to avoid "losing" the preimage. - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &cs_raa); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &cs_raa); check_added_monitors(&nodes[1], 0); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); } @@ -3085,8 +3086,8 @@ fn do_test_inverted_mon_completion_order(with_latest_manager: bool, complete_bc_ let mon_bc = get_monitor!(nodes[1], chan_id_bc).encode(); reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, new_chain_monitor, nodes_1_deserialized); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); if with_latest_manager { // If we used the latest ChannelManager to reload from, we should have both channels still @@ -3160,7 +3161,7 @@ fn do_test_inverted_mon_completion_order(with_latest_manager: bool, complete_bc_ let bs_updates = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); check_added_monitors(&nodes[1], 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); do_commitment_signed_dance(&nodes[0], &nodes[1], &bs_updates.commitment_signed, false, false); expect_payment_forwarded!(nodes[1], &nodes[0], &nodes[2], Some(1_000), false, !with_latest_manager); @@ -3213,7 +3214,7 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool, chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); let cs_updates = get_htlc_update_msgs(&nodes[2], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); // B generates a new monitor update for the A <-> B channel, but doesn't send the new messages // for it since the monitor update is marked in-progress. @@ -3223,7 +3224,7 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool, // Now step the Commitment Signed Dance between B and C forward a bit, ensuring we won't get // the preimage when the nodes reconnect, at which point we have to ensure we get it from the // ChannelMonitor. - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); check_added_monitors(&nodes[1], 1); let _ = get_revoke_commit_msgs!(nodes[1], nodes[2].node.get_our_node_id()); @@ -3248,8 +3249,8 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool, let manager_b = nodes[1].node.encode(); reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, new_chain_monitor, nodes_1_deserialized); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); if close_chans_before_reload { // If the channels were already closed, B will rebroadcast its closing transactions here. @@ -3366,20 +3367,20 @@ fn test_sync_async_persist_doesnt_hang() { expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000); let bs_updates = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); check_added_monitors(&nodes[0], 1); let (as_raa, as_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors(&nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs); check_added_monitors(&nodes[1], 1); let bs_final_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_final_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_final_raa); check_added_monitors(&nodes[0], 1); // Immediately complete the monitor update, but before the ChannelManager has a chance to see @@ -3393,8 +3394,8 @@ fn test_sync_async_persist_doesnt_hang() { expect_payment_claimed!(nodes[1], payment_hash_2, 1_000_000); let bs_updates = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); check_added_monitors(&nodes[0], 1); // At this point, we have completed an extra `ChannelMonitorUpdate` but the `ChannelManager` @@ -3416,13 +3417,13 @@ fn test_sync_async_persist_doesnt_hang() { } else { panic!(); } // Finally, complete the claiming of the second payment - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors(&nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs); check_added_monitors(&nodes[1], 1); let bs_final_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_final_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_final_raa); check_added_monitors(&nodes[0], 1); expect_payment_path_successful!(nodes[0]); } @@ -3456,7 +3457,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) { chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); let cs_updates = get_htlc_update_msgs(&nodes[2], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); // B generates a new monitor update for the A <-> B channel, but doesn't send the new messages // for it since the monitor update is marked in-progress. @@ -3465,17 +3466,17 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) { // Now step the Commitment Signed Dance between B and C and check that after the final RAA B // doesn't let the preimage-removing monitor update fly. - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &cs_updates.commitment_signed); check_added_monitors(&nodes[1], 1); let (bs_raa, bs_cs) = get_revoke_commit_msgs!(nodes[1], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors(&nodes[2], 1); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs); check_added_monitors(&nodes[2], 1); let cs_final_raa = get_event_msg!(nodes[2], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &cs_final_raa); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &cs_final_raa); check_added_monitors(&nodes[1], 0); // Finally, reload node B and check that after we call `process_pending_events` once we realize @@ -3519,7 +3520,7 @@ fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) { // Finally, check that there's nothing left to do on B<->C reconnect and the channel operates // fine. - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[1], &nodes[2])); send_payment(&nodes[1], &[&nodes[2]], 100_000); } @@ -3558,18 +3559,18 @@ fn do_test_glacial_peer_cant_hang(hold_chan_a: bool) { // The first update will be on the A <-> B channel, which we allow to complete. chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); } - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); check_added_monitors(&nodes[1], 1); if !hold_chan_a { let bs_updates = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false); expect_payment_sent!(&nodes[0], payment_preimage); } - nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); let mut reconnect = ReconnectArgs::new(&nodes[1], &nodes[2]); reconnect.pending_htlc_claims = (1, 0); @@ -3641,19 +3642,19 @@ fn test_partial_claim_mon_update_compl_actions() { expect_payment_claimed!(&nodes[3], payment_hash, 200_000); let updates = get_htlc_update_msgs(&nodes[3], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); check_added_monitors(&nodes[1], 1); expect_payment_forwarded!(nodes[1], nodes[0], nodes[3], Some(1000), false, false); let _bs_updates_for_a = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[3].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[3].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors(&nodes[1], 1); let (bs_raa, bs_cs) = get_revoke_commit_msgs(&nodes[1], &nodes[3].node.get_our_node_id()); - nodes[3].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[3].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors(&nodes[3], 0); - nodes[3].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs); + nodes[3].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs); check_added_monitors(&nodes[3], 0); assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty()); @@ -3670,7 +3671,7 @@ fn test_partial_claim_mon_update_compl_actions() { match remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut ds_msgs) { MessageSendEvent::SendRevokeAndACK { msg, .. } => { - nodes[1].node.handle_revoke_and_ack(&nodes[3].node.get_our_node_id(), &msg); + nodes[1].node.handle_revoke_and_ack(nodes[3].node.get_our_node_id(), &msg); check_added_monitors(&nodes[1], 1); } _ => panic!(), @@ -3678,12 +3679,12 @@ fn test_partial_claim_mon_update_compl_actions() { match remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut ds_msgs) { MessageSendEvent::UpdateHTLCs { updates, .. } => { - nodes[2].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[2].node.handle_update_fulfill_htlc(nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); check_added_monitors(&nodes[2], 1); expect_payment_forwarded!(nodes[2], nodes[0], nodes[3], Some(1000), false, false); let _cs_updates_for_a = get_htlc_update_msgs(&nodes[2], &nodes[0].node.get_our_node_id()); - nodes[2].node.handle_commitment_signed(&nodes[3].node.get_our_node_id(), &updates.commitment_signed); + nodes[2].node.handle_commitment_signed(nodes[3].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors(&nodes[2], 1); }, _ => panic!(), @@ -3691,14 +3692,14 @@ fn test_partial_claim_mon_update_compl_actions() { let (cs_raa, cs_cs) = get_revoke_commit_msgs(&nodes[2], &nodes[3].node.get_our_node_id()); - nodes[3].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &cs_raa); + nodes[3].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &cs_raa); check_added_monitors(&nodes[3], 1); - nodes[3].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_cs); + nodes[3].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &cs_cs); check_added_monitors(&nodes[3], 1); let ds_raa = get_event_msg!(nodes[3], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[3].node.get_our_node_id(), &ds_raa); + nodes[2].node.handle_revoke_and_ack(nodes[3].node.get_our_node_id(), &ds_raa); check_added_monitors(&nodes[2], 1); // Our current `ChannelMonitor`s store preimages one RAA longer than they need to. That's nice diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 641a61c3140..46b35a94038 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -79,9 +79,6 @@ pub struct ChannelValueStat { } pub struct AvailableBalances { - /// The amount that would go to us if we close the channel, ignoring any on-chain fees. - #[deprecated(since = "0.0.124", note = "use [`ChainMonitor::get_claimable_balances`] instead")] - pub balance_msat: u64, /// Total amount available for our counterparty to send to us. pub inbound_capacity_msat: u64, /// Total amount available for us to send to our counterparty. @@ -909,6 +906,7 @@ pub(super) struct SignerResumeUpdates { pub order: RAACommitmentOrder, pub closing_signed: Option, pub signed_closing_tx: Option, + pub shutdown_result: Option, } /// The return value of `channel_reestablish` @@ -3089,14 +3087,6 @@ impl ChannelContext where SP::Target: SignerProvider { let dust_exposure_limiting_feerate = self.get_dust_exposure_limiting_feerate(&fee_estimator); let htlc_stats = context.get_pending_htlc_stats(None, dust_exposure_limiting_feerate); - let mut balance_msat = context.value_to_self_msat; - for ref htlc in context.pending_inbound_htlcs.iter() { - if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state { - balance_msat += htlc.amount_msat; - } - } - balance_msat -= htlc_stats.pending_outbound_htlcs_value_msat; - let outbound_capacity_msat = context.value_to_self_msat .saturating_sub(htlc_stats.pending_outbound_htlcs_value_msat) .saturating_sub( @@ -3238,7 +3228,6 @@ impl ChannelContext where SP::Target: SignerProvider { outbound_capacity_msat, next_outbound_htlc_limit_msat: available_capacity_msat, next_outbound_htlc_minimum_msat, - balance_msat, } } @@ -5508,7 +5497,7 @@ impl Channel where commitment_update = None; } - let (closing_signed, signed_closing_tx) = if self.context.signer_pending_closing { + let (closing_signed, signed_closing_tx, shutdown_result) = if self.context.signer_pending_closing { debug_assert!(self.context.last_sent_closing_fee.is_some()); if let Some((fee, skip_remote_output, fee_range, holder_sig)) = self.context.last_sent_closing_fee.clone() { debug_assert!(holder_sig.is_none()); @@ -5524,19 +5513,21 @@ impl Channel where &self.context.get_counterparty_pubkeys().funding_pubkey).is_ok()); Some(self.build_signed_closing_transaction(&closing_tx, &counterparty_sig, signature)) } else { None }; - (closing_signed, signed_tx) - } else { (None, None) } - } else { (None, None) }; + let shutdown_result = signed_tx.as_ref().map(|_| self.shutdown_result_coop_close()); + (closing_signed, signed_tx, shutdown_result) + } else { (None, None, None) } + } else { (None, None, None) }; log_trace!(logger, "Signer unblocked with {} commitment_update, {} revoke_and_ack, with resend order {:?}, {} funding_signed, {} channel_ready, - {} closing_signed, and {} signed_closing_tx", + {} closing_signed, {} signed_closing_tx, and {} shutdown result", if commitment_update.is_some() { "a" } else { "no" }, if revoke_and_ack.is_some() { "a" } else { "no" }, self.context.resend_order, if funding_signed.is_some() { "a" } else { "no" }, if channel_ready.is_some() { "a" } else { "no" }, if closing_signed.is_some() { "a" } else { "no" }, - if signed_closing_tx.is_some() { "a" } else { "no" }); + if signed_closing_tx.is_some() { "a" } else { "no" }, + if shutdown_result.is_some() { "a" } else { "no" }); SignerResumeUpdates { commitment_update, @@ -5546,6 +5537,7 @@ impl Channel where order: self.context.resend_order.clone(), closing_signed, signed_closing_tx, + shutdown_result, } } @@ -6170,6 +6162,27 @@ impl Channel where }) } + fn shutdown_result_coop_close(&self) -> ShutdownResult { + let closure_reason = if self.initiated_shutdown() { + ClosureReason::LocallyInitiatedCooperativeClosure + } else { + ClosureReason::CounterpartyInitiatedCooperativeClosure + }; + ShutdownResult { + closure_reason, + monitor_update: None, + dropped_outbound_htlcs: Vec::new(), + unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(), + channel_id: self.context.channel_id, + user_channel_id: self.context.user_id, + channel_capacity_satoshis: self.context.channel_value_satoshis, + counterparty_node_id: self.context.counterparty_node_id, + unbroadcasted_funding_tx: self.context.unbroadcasted_funding(), + is_manual_broadcast: self.context.is_manual_broadcast, + channel_funding_txo: self.context.get_funding_txo(), + } + } + pub fn closing_signed( &mut self, fee_estimator: &LowerBoundedFeeEstimator, msg: &msgs::ClosingSigned, logger: &L) -> Result<(Option, Option, Option), ChannelError> @@ -6226,28 +6239,10 @@ impl Channel where } } - let closure_reason = if self.initiated_shutdown() { - ClosureReason::LocallyInitiatedCooperativeClosure - } else { - ClosureReason::CounterpartyInitiatedCooperativeClosure - }; - assert!(self.context.shutdown_scriptpubkey.is_some()); if let Some((last_fee, _, _, Some(sig))) = self.context.last_sent_closing_fee { if last_fee == msg.fee_satoshis { - let shutdown_result = ShutdownResult { - closure_reason, - monitor_update: None, - dropped_outbound_htlcs: Vec::new(), - unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(), - channel_id: self.context.channel_id, - user_channel_id: self.context.user_id, - channel_capacity_satoshis: self.context.channel_value_satoshis, - counterparty_node_id: self.context.counterparty_node_id, - unbroadcasted_funding_tx: self.context.unbroadcasted_funding(), - is_manual_broadcast: self.context.is_manual_broadcast, - channel_funding_txo: self.context.get_funding_txo(), - }; + let shutdown_result = self.shutdown_result_coop_close(); let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig); self.context.channel_state = ChannelState::ShutdownComplete; self.context.update_time_counter += 1; @@ -6268,19 +6263,8 @@ impl Channel where let closing_signed = self.get_closing_signed_msg(&closing_tx, skip_remote_output, used_fee, our_min_fee, our_max_fee, logger); let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis { - let shutdown_result = ShutdownResult { - closure_reason, - monitor_update: None, - dropped_outbound_htlcs: Vec::new(), - unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(), - channel_id: self.context.channel_id, - user_channel_id: self.context.user_id, - channel_capacity_satoshis: self.context.channel_value_satoshis, - counterparty_node_id: self.context.counterparty_node_id, - unbroadcasted_funding_tx: self.context.unbroadcasted_funding(), - is_manual_broadcast: self.context.is_manual_broadcast, - channel_funding_txo: self.context.get_funding_txo(), - }; + let shutdown_result = closing_signed.as_ref() + .map(|_| self.shutdown_result_coop_close()); if closing_signed.is_some() { self.context.channel_state = ChannelState::ShutdownComplete; } @@ -6288,7 +6272,7 @@ impl Channel where self.context.last_received_closing_sig = Some(msg.signature.clone()); let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }| self.build_signed_closing_transaction(&closing_tx, &msg.signature, signature)); - (tx, Some(shutdown_result)) + (tx, shutdown_result) } else { (None, None) }; diff --git a/lightning/src/ln/channel_state.rs b/lightning/src/ln/channel_state.rs index 97e6b0af10c..6f5ed5afe82 100644 --- a/lightning/src/ln/channel_state.rs +++ b/lightning/src/ln/channel_state.rs @@ -359,25 +359,11 @@ pub struct ChannelDetails { /// /// This value will be `None` for objects serialized with LDK versions prior to 0.0.115. pub feerate_sat_per_1000_weight: Option, - /// Our total balance. This is the amount we would get if we close the channel. - /// This value is not exact. Due to various in-flight changes and feerate changes, exactly this - /// amount is not likely to be recoverable on close. - /// - /// This does not include any pending HTLCs which are not yet fully resolved (and, thus, whose - /// balance is not available for inclusion in new outbound HTLCs). This further does not include - /// any pending outgoing HTLCs which are awaiting some other resolution to be sent. - /// This does not consider any on-chain fees. - /// - /// See also [`ChannelDetails::outbound_capacity_msat`] - #[deprecated(since = "0.0.124", note = "use [`ChainMonitor::get_claimable_balances`] instead")] - pub balance_msat: u64, /// The available outbound capacity for sending HTLCs to the remote peer. This does not include /// any pending HTLCs which are not yet fully resolved (and, thus, whose balance is not /// available for inclusion in new outbound HTLCs). This further does not include any pending /// outgoing HTLCs which are awaiting some other resolution to be sent. /// - /// See also [`ChannelDetails::balance_msat`] - /// /// This value is not exact. Due to various in-flight changes, feerate changes, and our /// conflict-avoidance policy, exactly this amount is not likely to be spendable. However, we /// should be able to spend nearly this amount. @@ -387,8 +373,8 @@ pub struct ChannelDetails { /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us /// to use a limit as close as possible to the HTLC limit we can currently send. /// - /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`], - /// [`ChannelDetails::balance_msat`], and [`ChannelDetails::outbound_capacity_msat`]. + /// See also [`ChannelDetails::next_outbound_htlc_minimum_msat`] and + /// [`ChannelDetails::outbound_capacity_msat`]. pub next_outbound_htlc_limit_msat: u64, /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of /// [`ChannelDetails::next_outbound_htlc_limit_msat`] but represents a lower-bound, rather than @@ -540,7 +526,6 @@ impl ChannelDetails { channel_value_satoshis: context.get_value_satoshis(), feerate_sat_per_1000_weight: Some(context.get_feerate_sat_per_1000_weight()), unspendable_punishment_reserve: to_self_reserve_satoshis, - balance_msat: balance.balance_msat, inbound_capacity_msat: balance.inbound_capacity_msat, outbound_capacity_msat: balance.outbound_capacity_msat, next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat, @@ -584,7 +569,7 @@ impl Writeable for ChannelDetails { (10, self.channel_value_satoshis, required), (12, self.unspendable_punishment_reserve, option), (14, user_channel_id_low, required), - (16, self.balance_msat, required), + (16, self.next_outbound_htlc_limit_msat, required), // Forwards compatibility for removed balance_msat field. (18, self.outbound_capacity_msat, required), (19, self.next_outbound_htlc_limit_msat, required), (20, self.inbound_capacity_msat, required), @@ -623,7 +608,7 @@ impl Readable for ChannelDetails { (10, channel_value_satoshis, required), (12, unspendable_punishment_reserve, option), (14, user_channel_id_low, required), - (16, balance_msat, required), + (16, _balance_msat, option), // Backwards compatibility for removed balance_msat field. (18, outbound_capacity_msat, required), // Note that by the time we get past the required read above, outbound_capacity_msat will be // filled in, so we can safely unwrap it here. @@ -651,7 +636,8 @@ impl Readable for ChannelDetails { let user_channel_id = user_channel_id_low as u128 + ((user_channel_id_high_opt.unwrap_or(0 as u64) as u128) << 64); - #[allow(deprecated)] // TODO: Remove once balance_msat is removed. + let _balance_msat: Option = _balance_msat; + Ok(Self { inbound_scid_alias, channel_id: channel_id.0.unwrap(), @@ -664,7 +650,6 @@ impl Readable for ChannelDetails { channel_value_satoshis: channel_value_satoshis.0.unwrap(), unspendable_punishment_reserve, user_channel_id, - balance_msat: balance_msat.0.unwrap(), outbound_capacity_msat: outbound_capacity_msat.0.unwrap(), next_outbound_htlc_limit_msat: next_outbound_htlc_limit_msat.0.unwrap(), next_outbound_htlc_minimum_msat: next_outbound_htlc_minimum_msat.0.unwrap(), @@ -762,7 +747,6 @@ mod tests { inbound_scid_alias: None, channel_value_satoshis: 50_100, user_channel_id: (u64::MAX as u128) + 1, // Gets us into the high bytes - balance_msat: 23_100, outbound_capacity_msat: 24_300, next_outbound_htlc_limit_msat: 20_000, next_outbound_htlc_minimum_msat: 132, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index b3047930f61..4f602d0e64c 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -33,7 +33,7 @@ use bitcoin::secp256k1::Secp256k1; use bitcoin::{secp256k1, Sequence}; use crate::events::FundingInfo; -use crate::blinded_path::message::{MessageContext, OffersContext}; +use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext}; use crate::blinded_path::NodeIdLookUp; use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode}; use crate::blinded_path::payment::{BlindedPaymentPath, Bolt12OfferContext, Bolt12RefundContext, PaymentConstraints, PaymentContext, ReceiveTlvs}; @@ -61,18 +61,20 @@ use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING}; use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError}; #[cfg(test)] use crate::ln::outbound_payment; -use crate::ln::outbound_payment::{OutboundPayments, PaymentAttempts, PendingOutboundPayment, SendAlongPathArgs, StaleExpiration}; +use crate::ln::outbound_payment::{OutboundPayments, PendingOutboundPayment, RetryableInvoiceRequest, SendAlongPathArgs, StaleExpiration}; use crate::ln::wire::Encode; use crate::offers::invoice::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice}; use crate::offers::invoice_error::InvoiceError; -use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder}; +use crate::offers::invoice_request::{DerivedPayerSigningPubkey, InvoiceRequest, InvoiceRequestBuilder}; use crate::offers::nonce::Nonce; use crate::offers::offer::{Offer, OfferBuilder}; use crate::offers::parse::Bolt12SemanticError; use crate::offers::refund::{Refund, RefundBuilder}; use crate::offers::signer; +#[cfg(async_payments)] +use crate::offers::static_invoice::StaticInvoice; use crate::onion_message::async_payments::{AsyncPaymentsMessage, HeldHtlcAvailable, ReleaseHeldHtlc, AsyncPaymentsMessageHandler}; -use crate::onion_message::messenger::{Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions}; +use crate::onion_message::messenger::{BlindedPathType, Destination, MessageRouter, Responder, ResponseInstruction, MessageSendInstructions}; use crate::onion_message::offers::{OffersMessage, OffersMessageHandler}; use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider}; use crate::sign::ecdsa::EcdsaChannelSigner; @@ -409,6 +411,38 @@ impl From<&ClaimableHTLC> for events::ClaimedHTLC { } } +/// A trait defining behavior for creating and verifing the HMAC for authenticating a given data. +pub trait Verification { + /// Constructs an HMAC to include in [`OffersContext`] for the data along with the given + /// [`Nonce`]. + fn hmac_for_offer_payment( + &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Hmac; + + /// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`]. + fn verify_for_offer_payment( + &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Result<(), ()>; +} + +impl Verification for PaymentHash { + /// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash + /// along with the given [`Nonce`]. + fn hmac_for_offer_payment( + &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Hmac { + signer::hmac_for_payment_hash(*self, nonce, expanded_key) + } + + /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an + /// [`OffersContext::InboundPayment`]. + fn verify_for_offer_payment( + &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Result<(), ()> { + signer::verify_payment_hash(*self, hmac, nonce, expanded_key) + } +} + /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify /// a payment and ensure idempotency in LDK. /// @@ -420,20 +454,40 @@ impl PaymentId { /// Number of bytes in the id. pub const LENGTH: usize = 32; + /// Constructs an HMAC to include in [`AsyncPaymentsContext::OutboundPayment`] for the payment id + /// along with the given [`Nonce`]. + #[cfg(async_payments)] + pub fn hmac_for_async_payment( + &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Hmac { + signer::hmac_for_async_payment_id(*self, nonce, expanded_key) + } + + /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an + /// [`AsyncPaymentsContext::OutboundPayment`]. + #[cfg(async_payments)] + pub fn verify_for_async_payment( + &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, + ) -> Result<(), ()> { + signer::verify_async_payment_id(*self, hmac, nonce, expanded_key) + } +} + +impl Verification for PaymentId { /// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id /// along with the given [`Nonce`]. - pub fn hmac_for_offer_payment( + fn hmac_for_offer_payment( &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Hmac { - signer::hmac_for_payment_id(*self, nonce, expanded_key) + signer::hmac_for_offer_payment_id(*self, nonce, expanded_key) } /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an /// [`OffersContext::OutboundPayment`]. - pub fn verify( + fn verify_for_offer_payment( &self, hmac: Hmac, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey, ) -> Result<(), ()> { - signer::verify_payment_id(*self, hmac, nonce, expanded_key) + signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key) } } @@ -1726,12 +1780,13 @@ where /// # use lightning::events::{Event, EventsProvider, PaymentPurpose}; /// # use lightning::ln::channelmanager::AChannelManager; /// # use lightning::offers::parse::Bolt12SemanticError; +/// # use lightning::onion_message::messenger::BlindedPathType; /// # /// # fn example(channel_manager: T) -> Result<(), Bolt12SemanticError> { /// # let channel_manager = channel_manager.get_cm(); -/// # let absolute_expiry = None; +/// # let blinded_path = BlindedPathType::Full; /// let offer = channel_manager -/// .create_offer_builder(absolute_expiry)? +/// .create_offer_builder(Some(blinded_path))? /// # ; /// # // Needed for compiling for c_bindings /// # let builder: lightning::offers::offer::OfferBuilder<_, _> = offer.into(); @@ -1829,6 +1884,7 @@ where /// # use lightning::events::{Event, EventsProvider}; /// # use lightning::ln::channelmanager::{AChannelManager, PaymentId, RecentPaymentDetails, Retry}; /// # use lightning::offers::parse::Bolt12SemanticError; +/// # use lightning::onion_message::messenger::BlindedPathType; /// # /// # fn example( /// # channel_manager: T, amount_msats: u64, absolute_expiry: Duration, retry: Retry, @@ -1836,9 +1892,10 @@ where /// # ) -> Result<(), Bolt12SemanticError> { /// # let channel_manager = channel_manager.get_cm(); /// let payment_id = PaymentId([42; 32]); +/// let blinded_path = Some(BlindedPathType::Full); /// let refund = channel_manager /// .create_refund_builder( -/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat +/// amount_msats, absolute_expiry, payment_id, retry, max_total_routing_fee_msat, blinded_path /// )? /// # ; /// # // Needed for compiling for c_bindings @@ -2026,6 +2083,8 @@ where // // `pending_offers_messages` // +// `pending_async_payments_messages` +// // `total_consistency_lock` // | // |__`forward_htlcs` @@ -2281,6 +2340,7 @@ where pending_offers_messages: Mutex>, #[cfg(any(test, feature = "_test_utils"))] pub(crate) pending_offers_messages: Mutex>, + pending_async_payments_messages: Mutex>, /// Tracks the message events that are to be broadcasted when we are connected to some peer. pending_broadcast_messages: Mutex>, @@ -2494,9 +2554,7 @@ const MAX_NO_CHANNEL_PEERS: usize = 250; /// short-lived, while anything with a greater expiration is considered long-lived. /// /// Using [`ChannelManager::create_offer_builder`] or [`ChannelManager::create_refund_builder`], -/// will included a [`BlindedMessagePath`] created using: -/// - [`MessageRouter::create_compact_blinded_paths`] when short-lived, and -/// - [`MessageRouter::create_blinded_paths`] when long-lived. +/// will included a [`BlindedMessagePath`] created using [`MessageRouter::create_blinded_paths`]. /// /// Using compact [`BlindedMessagePath`]s may provide better privacy as the [`MessageRouter`] could select /// more hops. However, since they use short channel ids instead of pubkeys, they are more likely to @@ -2509,14 +2567,17 @@ pub const MAX_SHORT_LIVED_RELATIVE_EXPIRY: Duration = Duration::from_secs(60 * 6 pub enum RecentPaymentDetails { /// When an invoice was requested and thus a payment has not yet been sent. AwaitingInvoice { - /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify - /// a payment and ensure idempotency in LDK. + /// A user-provided identifier in [`ChannelManager::pay_for_offer`] used to uniquely identify a + /// payment and ensure idempotency in LDK. payment_id: PaymentId, }, /// When a payment is still being sent and awaiting successful delivery. Pending { - /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify - /// a payment and ensure idempotency in LDK. + /// A user-provided identifier in [`send_payment`] or [`pay_for_offer`] used to uniquely + /// identify a payment and ensure idempotency in LDK. + /// + /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager::pay_for_offer payment_id: PaymentId, /// Hash of the payment that is currently being sent but has yet to be fulfilled or /// abandoned. @@ -2529,8 +2590,11 @@ pub enum RecentPaymentDetails { /// been resolved. Upon receiving [`Event::PaymentSent`], we delay for a few minutes before the /// payment is removed from tracking. Fulfilled { - /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify - /// a payment and ensure idempotency in LDK. + /// A user-provided identifier in [`send_payment`] or [`pay_for_offer`] used to uniquely + /// identify a payment and ensure idempotency in LDK. + /// + /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager::pay_for_offer payment_id: PaymentId, /// Hash of the payment that was claimed. `None` for serializations of [`ChannelManager`] /// made before LDK version 0.0.104. @@ -2540,8 +2604,11 @@ pub enum RecentPaymentDetails { /// abandoned via [`ChannelManager::abandon_payment`], it is marked as abandoned until all /// pending HTLCs for this payment resolve and an [`Event::PaymentFailed`] is generated. Abandoned { - /// A user-provided identifier in [`ChannelManager::send_payment`] used to uniquely identify - /// a payment and ensure idempotency in LDK. + /// A user-provided identifier in [`send_payment`] or [`pay_for_offer`] used to uniquely + /// identify a payment and ensure idempotency in LDK. + /// + /// [`send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`pay_for_offer`]: crate::ln::channelmanager::ChannelManager::pay_for_offer payment_id: PaymentId, /// Hash of the payment that we have given up trying to send. payment_hash: PaymentHash, @@ -3071,7 +3138,7 @@ where outbound_scid_aliases: Mutex::new(new_hash_set()), pending_inbound_payments: Mutex::new(new_hash_map()), - pending_outbound_payments: OutboundPayments::new(), + pending_outbound_payments: OutboundPayments::new(new_hash_map()), forward_htlcs: Mutex::new(new_hash_map()), decode_update_add_htlcs: Mutex::new(new_hash_map()), claimable_payments: Mutex::new(ClaimablePayments { claimable_payments: new_hash_map(), pending_claiming_payments: new_hash_map() }), @@ -3101,6 +3168,7 @@ where funding_batch_states: Mutex::new(BTreeMap::new()), pending_offers_messages: Mutex::new(Vec::new()), + pending_async_payments_messages: Mutex::new(Vec::new()), pending_broadcast_messages: Mutex::new(Vec::new()), last_days_feerates: Mutex::new(VecDeque::new()), @@ -3336,6 +3404,9 @@ where PendingOutboundPayment::InvoiceReceived { .. } => { Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id }) }, + PendingOutboundPayment::StaticInvoiceReceived { .. } => { + Some(RecentPaymentDetails::AwaitingInvoice { payment_id: *payment_id }) + }, PendingOutboundPayment::Retryable { payment_hash, total_msat, .. } => { Some(RecentPaymentDetails::Pending { payment_id: *payment_id, @@ -3625,7 +3696,7 @@ where let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); log_debug!(self.logger, "Force-closing channel, The error message sent to the peer : {}", error_message); - match self.force_close_channel_with_peer(channel_id, counterparty_node_id, None, broadcast) { + match self.force_close_channel_with_peer(channel_id, &counterparty_node_id, None, broadcast) { Ok(counterparty_node_id) => { let per_peer_state = self.per_peer_state.read().unwrap(); if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) { @@ -4277,6 +4348,92 @@ where ) } + #[cfg(async_payments)] + fn initiate_async_payment( + &self, invoice: &StaticInvoice, payment_id: PaymentId + ) -> Result<(), Bolt12PaymentError> { + let mut res = Ok(()); + PersistenceNotifierGuard::optionally_notify(self, || { + let best_block_height = self.best_block.read().unwrap().height; + let features = self.bolt12_invoice_features(); + let outbound_pmts_res = self.pending_outbound_payments.static_invoice_received( + invoice, payment_id, features, best_block_height, &*self.entropy_source, + &self.pending_events + ); + match outbound_pmts_res { + Ok(()) => {}, + Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => { + res = outbound_pmts_res.map(|_| ()); + return NotifyOption::SkipPersistNoEvents + }, + Err(e) => { + res = Err(e); + return NotifyOption::DoPersist + } + }; + + let nonce = Nonce::from_entropy_source(&*self.entropy_source); + let hmac = payment_id.hmac_for_async_payment(nonce, &self.inbound_payment_key); + let reply_paths = match self.create_blinded_paths( + MessageContext::AsyncPayments( + AsyncPaymentsContext::OutboundPayment { payment_id, nonce, hmac } + ) + ) { + Ok(paths) => paths, + Err(()) => { + self.abandon_payment_with_reason(payment_id, PaymentFailureReason::RouteNotFound); + res = Err(Bolt12PaymentError::BlindedPathCreationFailed); + return NotifyOption::DoPersist + } + }; + + let mut pending_async_payments_messages = self.pending_async_payments_messages.lock().unwrap(); + const HTLC_AVAILABLE_LIMIT: usize = 10; + reply_paths + .iter() + .flat_map(|reply_path| invoice.message_paths().iter().map(move |invoice_path| (invoice_path, reply_path))) + .take(HTLC_AVAILABLE_LIMIT) + .for_each(|(invoice_path, reply_path)| { + let instructions = MessageSendInstructions::WithSpecifiedReplyPath { + destination: Destination::BlindedPath(invoice_path.clone()), + reply_path: reply_path.clone(), + }; + let message = AsyncPaymentsMessage::HeldHtlcAvailable(HeldHtlcAvailable {}); + pending_async_payments_messages.push((message, instructions)); + }); + + NotifyOption::DoPersist + }); + + res + } + + #[cfg(async_payments)] + fn send_payment_for_static_invoice( + &self, payment_id: PaymentId + ) -> Result<(), Bolt12PaymentError> { + let best_block_height = self.best_block.read().unwrap().height; + let mut res = Ok(()); + PersistenceNotifierGuard::optionally_notify(self, || { + let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice( + payment_id, &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(), + &self.entropy_source, &self.node_signer, &self, &self.secp_ctx, best_block_height, + &self.logger, &self.pending_events, |args| self.send_payment_along_path(args) + ); + match outbound_pmts_res { + Err(Bolt12PaymentError::UnexpectedInvoice) | Err(Bolt12PaymentError::DuplicateInvoice) => { + res = outbound_pmts_res.map(|_| ()); + NotifyOption::SkipPersistNoEvents + }, + other_res => { + res = other_res; + NotifyOption::DoPersist + } + } + }); + res + } + /// Signals that no further attempts for the given payment should occur. Useful if you have a /// pending outbound payment with retries remaining, but wish to stop retrying the payment before /// retries are exhausted. @@ -5886,7 +6043,7 @@ where /// * Forgetting about stale outbound payments, either those that have already been fulfilled /// or those awaiting an invoice that hasn't been delivered in the necessary amount of time. /// The latter is determined using the system clock in `std` and the highest seen block time - /// minus two hours in `no-std`. + /// minus two hours in non-`std`. /// /// Note that this may cause reentrancy through [`chain::Watch::update_channel`] calls or feerate /// estimate fetches. @@ -7135,7 +7292,7 @@ where chan } else { let update_actions = peer_state.monitor_update_blocked_actions - .remove(&channel_id).unwrap_or(Vec::new()); + .remove(channel_id).unwrap_or(Vec::new()); mem::drop(peer_state_lock); mem::drop(per_peer_state); self.handle_monitor_update_completion_actions(update_actions); @@ -7827,7 +7984,7 @@ where if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() { let logger = WithChannelContext::from(&self.logger, &chan.context, None); let (closing_signed, tx, shutdown_result) = try_chan_phase_entry!(self, chan.closing_signed(&self.fee_estimator, &msg, &&logger), chan_phase_entry); - debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown() || chan.is_shutdown_pending_signature()); + debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown()); if let Some(msg) = closing_signed { peer_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned { node_id: counterparty_node_id.clone(), @@ -8650,7 +8807,7 @@ where let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); // Returns whether we should remove this channel as it's just been closed. - let unblock_chan = |phase: &mut ChannelPhase, pending_msg_events: &mut Vec| -> bool { + let unblock_chan = |phase: &mut ChannelPhase, pending_msg_events: &mut Vec| -> Option { let node_id = phase.context().get_counterparty_node_id(); match phase { ChannelPhase::Funded(chan) => { @@ -8703,11 +8860,8 @@ where msg: update }); } - - // We should return true to remove the channel if we just - // broadcasted the closing transaction. - true - } else { false } + } + msgs.shutdown_result } ChannelPhase::UnfundedOutboundV1(chan) => { if let Some(msg) = chan.signer_maybe_unblocked(&self.logger) { @@ -8716,12 +8870,13 @@ where msg, }); } - false + None } - ChannelPhase::UnfundedInboundV1(_) => false, + ChannelPhase::UnfundedInboundV1(_) => None, } }; + let mut shutdown_results = Vec::new(); let per_peer_state = self.per_peer_state.read().unwrap(); let per_peer_state_iter = per_peer_state.iter().filter(|(cp_id, _)| { if let Some((counterparty_node_id, _)) = channel_opt { @@ -8732,16 +8887,23 @@ where let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; peer_state.channel_by_id.retain(|_, chan| { - let should_remove = match channel_opt { - Some((_, channel_id)) if chan.context().channel_id() != channel_id => false, + let shutdown_result = match channel_opt { + Some((_, channel_id)) if chan.context().channel_id() != channel_id => None, _ => unblock_chan(chan, &mut peer_state.pending_msg_events), }; - if should_remove { + if let Some(shutdown_result) = shutdown_result { log_trace!(self.logger, "Removing channel after unblocking signer"); + shutdown_results.push(shutdown_result); + false + } else { + true } - !should_remove }); } + drop(per_peer_state); + for shutdown_result in shutdown_results.drain(..) { + self.finish_close_channel(shutdown_result); + } } /// Check whether any channels have finished removing all pending updates after a shutdown @@ -8770,8 +8932,8 @@ where node_id: chan.context.get_counterparty_node_id(), msg, }); } + debug_assert_eq!(shutdown_result_opt.is_some(), chan.is_shutdown()); if let Some(shutdown_result) = shutdown_result_opt { - debug_assert!(chan.is_shutdown() || chan.is_shutdown_pending_signature()); shutdown_results.push(shutdown_result); } if let Some(tx) = tx_opt { @@ -8868,7 +9030,7 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => { /// [`Offer`]: crate::offers::offer::Offer /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest pub fn create_offer_builder( - &$self, absolute_expiry: Option + &$self, blinded_path: Option, ) -> Result<$builder, Bolt12SemanticError> { let node_id = $self.get_our_node_id(); let expanded_key = &$self.inbound_payment_key; @@ -8876,17 +9038,23 @@ macro_rules! create_offer_builder { ($self: ident, $builder: ty) => { let secp_ctx = &$self.secp_ctx; let nonce = Nonce::from_entropy_source(entropy); - let context = OffersContext::InvoiceRequest { nonce }; - let path = $self.create_blinded_paths_using_absolute_expiry(context, absolute_expiry) - .and_then(|paths| paths.into_iter().next().ok_or(())) - .map_err(|_| Bolt12SemanticError::MissingPaths)?; - let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx) - .chain_hash($self.chain_hash) - .path(path); + let context = MessageContext::Offers( + OffersContext::InvoiceRequest { nonce } + ); + let builder = match blinded_path { + Some(blinded_path) => { + let path = $self + .create_blinded_paths(context, blinded_path) + .and_then(|paths| paths.into_iter().next().ok_or(())) + .map_err(|_| Bolt12SemanticError::MissingPaths)?; - let builder = match absolute_expiry { - None => builder, - Some(absolute_expiry) => builder.absolute_expiry(absolute_expiry), + OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx) + .chain_hash($self.chain_hash) + .path(path) + } + + None => OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx) + .chain_hash($self.chain_hash), }; Ok(builder.into()) @@ -8903,7 +9071,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { /// See [Avoiding Duplicate Payments] for other requirements once the payment has been sent. /// /// The builder will have the provided expiration set. Any changes to the expiration on the - /// returned builder will not be honored by [`ChannelManager`]. For `no-std`, the highest seen + /// returned builder will not be honored by [`ChannelManager`]. For non-`std`, the highest seen /// block time minus two hours is used for the current time when determining if the refund has /// expired. /// @@ -8941,7 +9109,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { /// [Avoiding Duplicate Payments]: #avoiding-duplicate-payments pub fn create_refund_builder( &$self, amount_msats: u64, absolute_expiry: Duration, payment_id: PaymentId, - retry_strategy: Retry, max_total_routing_fee_msat: Option + retry_strategy: Retry, max_total_routing_fee_msat: Option, blinded_path: Option ) -> Result<$builder, Bolt12SemanticError> { let node_id = $self.get_our_node_id(); let expanded_key = &$self.inbound_payment_key; @@ -8949,24 +9117,41 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => { let secp_ctx = &$self.secp_ctx; let nonce = Nonce::from_entropy_source(entropy); - let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None }; - let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry)) - .and_then(|paths| paths.into_iter().next().ok_or(())) - .map_err(|_| Bolt12SemanticError::MissingPaths)?; + let context = MessageContext::Offers( + OffersContext::OutboundPayment { payment_id, nonce, hmac: None } + ); + + let builder = match blinded_path { + Some(blinded_path) => { + let path = $self + .create_blinded_paths(context, blinded_path) + .and_then(|paths| paths.into_iter().next().ok_or(())) + .map_err(|_| Bolt12SemanticError::MissingPaths)?; + + RefundBuilder::deriving_signing_pubkey( + node_id, expanded_key, nonce, secp_ctx, + amount_msats, payment_id, + )? + .chain_hash($self.chain_hash) + .absolute_expiry(absolute_expiry) + .path(path) + } - let builder = RefundBuilder::deriving_payer_id( - node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id - )? + None => RefundBuilder::deriving_signing_pubkey( + node_id, expanded_key, nonce, secp_ctx, + amount_msats, payment_id, + )? .chain_hash($self.chain_hash) .absolute_expiry(absolute_expiry) - .path(path); + .absolute_expiry(absolute_expiry), + }; let _persistence_guard = PersistenceNotifierGuard::notify_on_drop($self); let expiration = StaleExpiration::AbsoluteTimeout(absolute_expiry); $self.pending_outbound_payments .add_new_awaiting_invoice( - payment_id, expiration, retry_strategy, max_total_routing_fee_msat, + payment_id, expiration, retry_strategy, max_total_routing_fee_msat, None, ) .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?; @@ -9036,7 +9221,7 @@ where /// # Limitations /// /// Requires a direct connection to an introduction node in [`Offer::paths`] or to - /// [`Offer::signing_pubkey`], if empty. A similar restriction applies to the responding + /// [`Offer::issuer_signing_pubkey`], if empty. A similar restriction applies to the responding /// [`Bolt12Invoice::payment_paths`]. /// /// # Errors @@ -9065,8 +9250,8 @@ where let secp_ctx = &self.secp_ctx; let nonce = Nonce::from_entropy_source(entropy); - let builder: InvoiceRequestBuilder = offer - .request_invoice_deriving_payer_id(expanded_key, nonce, secp_ctx, payment_id)? + let builder: InvoiceRequestBuilder = offer + .request_invoice_deriving_signing_pubkey(expanded_key, nonce, secp_ctx, payment_id)? .into(); let builder = builder.chain_hash(self.chain_hash)?; @@ -9085,24 +9270,39 @@ where let invoice_request = builder.build_and_sign()?; let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key); - let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }; - let reply_paths = self.create_blinded_paths(context) + let context = MessageContext::Offers( + OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) } + ); + let reply_paths = self.create_blinded_paths(context, BlindedPathType::Full) .map_err(|_| Bolt12SemanticError::MissingPaths)?; let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); let expiration = StaleExpiration::TimerTicks(1); + let retryable_invoice_request = RetryableInvoiceRequest { + invoice_request: invoice_request.clone(), + nonce, + }; self.pending_outbound_payments .add_new_awaiting_invoice( - payment_id, expiration, retry_strategy, max_total_routing_fee_msat + payment_id, expiration, retry_strategy, max_total_routing_fee_msat, + Some(retryable_invoice_request) ) .map_err(|_| Bolt12SemanticError::DuplicatePaymentId)?; + self.enqueue_invoice_request(invoice_request, reply_paths) + } + + fn enqueue_invoice_request( + &self, + invoice_request: InvoiceRequest, + reply_paths: Vec, + ) -> Result<(), Bolt12SemanticError> { let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap(); - if !offer.paths().is_empty() { + if !invoice_request.paths().is_empty() { reply_paths .iter() - .flat_map(|reply_path| offer.paths().iter().map(move |path| (path, reply_path))) + .flat_map(|reply_path| invoice_request.paths().iter().map(move |path| (path, reply_path))) .take(OFFERS_MESSAGE_REQUEST_LIMIT) .for_each(|(path, reply_path)| { let instructions = MessageSendInstructions::WithSpecifiedReplyPath { @@ -9112,10 +9312,10 @@ where let message = OffersMessage::InvoiceRequest(invoice_request.clone()); pending_offers_messages.push((message, instructions)); }); - } else if let Some(signing_pubkey) = offer.signing_pubkey() { + } else if let Some(node_id) = invoice_request.issuer_signing_pubkey() { for reply_path in reply_paths { let instructions = MessageSendInstructions::WithSpecifiedReplyPath { - destination: Destination::Node(signing_pubkey), + destination: Destination::Node(node_id), reply_path, }; let message = OffersMessage::InvoiceRequest(invoice_request.clone()); @@ -9123,7 +9323,7 @@ where } } else { debug_assert!(false); - return Err(Bolt12SemanticError::MissingSigningPubkey); + return Err(Bolt12SemanticError::MissingIssuerSigningPubkey); } Ok(()) @@ -9139,9 +9339,9 @@ where /// # Limitations /// /// Requires a direct connection to an introduction node in [`Refund::paths`] or to - /// [`Refund::payer_id`], if empty. This request is best effort; an invoice will be sent to each - /// node meeting the aforementioned criteria, but there's no guarantee that they will be - /// received and no retries will be made. + /// [`Refund::payer_signing_pubkey`], if empty. This request is best effort; an invoice will be + /// sent to each node meeting the aforementioned criteria, but there's no guarantee that they + /// will be received and no retries will be made. /// /// # Errors /// @@ -9190,17 +9390,19 @@ where let builder: InvoiceBuilder = builder.into(); let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?; - let context = OffersContext::InboundPayment { - payment_hash: invoice.payment_hash(), - }; - let reply_paths = self.create_blinded_paths(context) + let nonce = Nonce::from_entropy_source(entropy); + let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key); + let context = MessageContext::Offers(OffersContext::InboundPayment { + payment_hash: invoice.payment_hash(), nonce, hmac + }); + let reply_paths = self.create_blinded_paths(context, BlindedPathType::Full) .map_err(|_| Bolt12SemanticError::MissingPaths)?; let mut pending_offers_messages = self.pending_offers_messages.lock().unwrap(); if refund.paths().is_empty() { for reply_path in reply_paths { let instructions = MessageSendInstructions::WithSpecifiedReplyPath { - destination: Destination::Node(refund.payer_id()), + destination: Destination::Node(refund.payer_signing_pubkey()), reply_path, }; let message = OffersMessage::Invoice(invoice.clone()); @@ -9325,25 +9527,7 @@ where inbound_payment::get_payment_preimage(payment_hash, payment_secret, &self.inbound_payment_key) } - /// Creates a collection of blinded paths by delegating to [`MessageRouter`] based on - /// the path's intended lifetime. - /// - /// Whether or not the path is compact depends on whether the path is short-lived or long-lived, - /// respectively, based on the given `absolute_expiry` as seconds since the Unix epoch. See - /// [`MAX_SHORT_LIVED_RELATIVE_EXPIRY`]. - fn create_blinded_paths_using_absolute_expiry( - &self, context: OffersContext, absolute_expiry: Option, - ) -> Result, ()> { - let now = self.duration_since_epoch(); - let max_short_lived_absolute_expiry = now.saturating_add(MAX_SHORT_LIVED_RELATIVE_EXPIRY); - - if absolute_expiry.unwrap_or(Duration::MAX) <= max_short_lived_absolute_expiry { - self.create_compact_blinded_paths(context) - } else { - self.create_blinded_paths(context) - } - } - + #[cfg(test)] pub(super) fn duration_since_epoch(&self) -> Duration { #[cfg(not(feature = "std"))] let now = Duration::from_secs( @@ -9361,28 +9545,7 @@ where /// [`MessageRouter::create_blinded_paths`]. /// /// Errors if the `MessageRouter` errors. - fn create_blinded_paths(&self, context: OffersContext) -> Result, ()> { - let recipient = self.get_our_node_id(); - let secp_ctx = &self.secp_ctx; - - let peers = self.per_peer_state.read().unwrap() - .iter() - .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap())) - .filter(|(_, peer)| peer.is_connected) - .filter(|(_, peer)| peer.latest_features.supports_onion_messages()) - .map(|(node_id, _)| *node_id) - .collect::>(); - - self.router - .create_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx) - .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(())) - } - - /// Creates a collection of blinded paths by delegating to - /// [`MessageRouter::create_compact_blinded_paths`]. - /// - /// Errors if the `MessageRouter` errors. - fn create_compact_blinded_paths(&self, context: OffersContext) -> Result, ()> { + fn create_blinded_paths(&self, context: MessageContext, blinded_path: BlindedPathType) -> Result, ()> { let recipient = self.get_our_node_id(); let secp_ctx = &self.secp_ctx; @@ -9391,18 +9554,30 @@ where .map(|(node_id, peer_state)| (node_id, peer_state.lock().unwrap())) .filter(|(_, peer)| peer.is_connected) .filter(|(_, peer)| peer.latest_features.supports_onion_messages()) - .map(|(node_id, peer)| MessageForwardNode { - node_id: *node_id, - short_channel_id: peer.channel_by_id - .iter() - .filter(|(_, channel)| channel.context().is_usable()) - .min_by_key(|(_, channel)| channel.context().channel_creation_height) - .and_then(|(_, channel)| channel.context().get_short_channel_id()), + .map(|(node_id, peer)| { + match blinded_path { + BlindedPathType::Full => { + MessageForwardNode { + node_id: *node_id, + short_channel_id: None, + } + } + BlindedPathType::Compact => { + MessageForwardNode { + node_id: *node_id, + short_channel_id: peer.channel_by_id + .iter() + .filter(|(_, channel)| channel.context().is_usable()) + .min_by_key(|(_, channel)| channel.context().channel_creation_height) + .and_then(|(_, channel)| channel.context().get_short_channel_id()), + } + } + } }) .collect::>(); self.router - .create_compact_blinded_paths(recipient, MessageContext::Offers(context), peers, secp_ctx) + .create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx) .and_then(|paths| (!paths.is_empty()).then(|| paths).ok_or(())) } @@ -10152,12 +10327,12 @@ where R::Target: Router, L::Target: Logger, { - fn handle_open_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannel) { + fn handle_open_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::OpenChannel) { // Note that we never need to persist the updated ChannelManager for an inbound // open_channel message - pre-funded channels are never written so there should be no // change to the contents. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_open_channel(counterparty_node_id, msg); + let res = self.internal_open_channel(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => { debug_assert!(false, "We shouldn't close a new channel"); @@ -10165,183 +10340,183 @@ where }, _ => NotifyOption::SkipPersistHandleEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + 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.common_fields.temporary_channel_id.clone())), *counterparty_node_id); + msg.common_fields.temporary_channel_id.clone())), counterparty_node_id); } - fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannel) { + fn handle_accept_channel(&self, counterparty_node_id: PublicKey, msg: &msgs::AcceptChannel) { // Note that we never need to persist the updated ChannelManager for an inbound // accept_channel message - pre-funded channels are never written so there should be no // change to the contents. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let _ = handle_error!(self, self.internal_accept_channel(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_accept_channel(&counterparty_node_id, msg), counterparty_node_id); NotifyOption::SkipPersistHandleEvents }); } - fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) { + 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.common_fields.temporary_channel_id.clone())), *counterparty_node_id); + msg.common_fields.temporary_channel_id.clone())), counterparty_node_id); } - fn handle_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) { + fn handle_funding_created(&self, counterparty_node_id: PublicKey, msg: &msgs::FundingCreated) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_funding_created(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_funding_created(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_funding_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingSigned) { + fn handle_funding_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::FundingSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_funding_signed(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_funding_signed(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_channel_ready(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReady) { + fn handle_channel_ready(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelReady) { // Note that we never need to persist the updated ChannelManager for an inbound // channel_ready message - while the channel's state will change, any channel_ready message // will ultimately be re-sent on startup and the `ChannelMonitor` won't be updated so we // will not force-close the channel on startup. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_channel_ready(counterparty_node_id, msg); + let res = self.internal_channel_ready(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, _ => NotifyOption::SkipPersistHandleEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_stfu(&self, counterparty_node_id: &PublicKey, msg: &msgs::Stfu) { + fn handle_stfu(&self, counterparty_node_id: PublicKey, msg: &msgs::Stfu) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Quiescence not supported".to_owned(), - msg.channel_id.clone())), *counterparty_node_id); + msg.channel_id.clone())), counterparty_node_id); } #[cfg(splicing)] - fn handle_splice_init(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceInit) { + fn handle_splice_init(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceInit) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Splicing not supported".to_owned(), - msg.channel_id.clone())), *counterparty_node_id); + msg.channel_id.clone())), counterparty_node_id); } #[cfg(splicing)] - fn handle_splice_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceAck) { + fn handle_splice_ack(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceAck) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Splicing not supported (splice_ack)".to_owned(), - msg.channel_id.clone())), *counterparty_node_id); + msg.channel_id.clone())), counterparty_node_id); } #[cfg(splicing)] - fn handle_splice_locked(&self, counterparty_node_id: &PublicKey, msg: &msgs::SpliceLocked) { + fn handle_splice_locked(&self, counterparty_node_id: PublicKey, msg: &msgs::SpliceLocked) { let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close( "Splicing not supported (splice_locked)".to_owned(), - msg.channel_id.clone())), *counterparty_node_id); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_shutdown(&self, counterparty_node_id: &PublicKey, msg: &msgs::Shutdown) { + fn handle_shutdown(&self, counterparty_node_id: PublicKey, msg: &msgs::Shutdown) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_shutdown(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_shutdown(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_closing_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::ClosingSigned) { + fn handle_closing_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::ClosingSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_closing_signed(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_closing_signed(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_update_add_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) { + fn handle_update_add_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateAddHTLC) { // Note that we never need to persist the updated ChannelManager for an inbound // update_add_htlc message - the message itself doesn't change our channel state only the // `commitment_signed` message afterwards will. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_update_add_htlc(counterparty_node_id, msg); + let res = self.internal_update_add_htlc(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, Err(_) => NotifyOption::SkipPersistHandleEvents, Ok(()) => NotifyOption::SkipPersistNoEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_update_fulfill_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) { + fn handle_update_fulfill_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFulfillHTLC) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_update_fulfill_htlc(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_update_fulfill_htlc(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_update_fail_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) { + fn handle_update_fail_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFailHTLC) { // Note that we never need to persist the updated ChannelManager for an inbound // update_fail_htlc message - the message itself doesn't change our channel state only the // `commitment_signed` message afterwards will. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_update_fail_htlc(counterparty_node_id, msg); + let res = self.internal_update_fail_htlc(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, Err(_) => NotifyOption::SkipPersistHandleEvents, Ok(()) => NotifyOption::SkipPersistNoEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_update_fail_malformed_htlc(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { + fn handle_update_fail_malformed_htlc(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { // Note that we never need to persist the updated ChannelManager for an inbound // update_fail_malformed_htlc message - the message itself doesn't change our channel state // only the `commitment_signed` message afterwards will. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_update_fail_malformed_htlc(counterparty_node_id, msg); + let res = self.internal_update_fail_malformed_htlc(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, Err(_) => NotifyOption::SkipPersistHandleEvents, Ok(()) => NotifyOption::SkipPersistNoEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_commitment_signed(&self, counterparty_node_id: &PublicKey, msg: &msgs::CommitmentSigned) { + fn handle_commitment_signed(&self, counterparty_node_id: PublicKey, msg: &msgs::CommitmentSigned) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_commitment_signed(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_commitment_signed(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_revoke_and_ack(&self, counterparty_node_id: &PublicKey, msg: &msgs::RevokeAndACK) { + fn handle_revoke_and_ack(&self, counterparty_node_id: PublicKey, msg: &msgs::RevokeAndACK) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_revoke_and_ack(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_revoke_and_ack(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_update_fee(&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFee) { + fn handle_update_fee(&self, counterparty_node_id: PublicKey, msg: &msgs::UpdateFee) { // Note that we never need to persist the updated ChannelManager for an inbound // update_fee message - the message itself doesn't change our channel state only the // `commitment_signed` message afterwards will. let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_update_fee(counterparty_node_id, msg); + let res = self.internal_update_fee(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, Err(_) => NotifyOption::SkipPersistHandleEvents, Ok(()) => NotifyOption::SkipPersistNoEvents, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn handle_announcement_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) { + fn handle_announcement_signatures(&self, counterparty_node_id: PublicKey, msg: &msgs::AnnouncementSignatures) { let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self); - let _ = handle_error!(self, self.internal_announcement_signatures(counterparty_node_id, msg), *counterparty_node_id); + let _ = handle_error!(self, self.internal_announcement_signatures(&counterparty_node_id, msg), counterparty_node_id); } - fn handle_channel_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelUpdate) { + fn handle_channel_update(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelUpdate) { PersistenceNotifierGuard::optionally_notify(self, || { - if let Ok(persist) = handle_error!(self, self.internal_channel_update(counterparty_node_id, msg), *counterparty_node_id) { + if let Ok(persist) = handle_error!(self, self.internal_channel_update(&counterparty_node_id, msg), counterparty_node_id) { persist } else { NotifyOption::DoPersist @@ -10349,31 +10524,31 @@ where }); } - fn handle_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { + fn handle_channel_reestablish(&self, counterparty_node_id: PublicKey, msg: &msgs::ChannelReestablish) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify(self, || { - let res = self.internal_channel_reestablish(counterparty_node_id, msg); + let res = self.internal_channel_reestablish(&counterparty_node_id, msg); let persist = match &res { Err(e) if e.closes_channel() => NotifyOption::DoPersist, Err(_) => NotifyOption::SkipPersistHandleEvents, Ok(persist) => *persist, }; - let _ = handle_error!(self, res, *counterparty_node_id); + let _ = handle_error!(self, res, counterparty_node_id); persist }); } - fn peer_disconnected(&self, counterparty_node_id: &PublicKey) { + fn peer_disconnected(&self, counterparty_node_id: PublicKey) { let _persistence_guard = PersistenceNotifierGuard::optionally_notify( self, || NotifyOption::SkipPersistHandleEvents); let mut failed_channels = Vec::new(); let mut per_peer_state = self.per_peer_state.write().unwrap(); let remove_peer = { log_debug!( - WithContext::from(&self.logger, Some(*counterparty_node_id), None, None), + WithContext::from(&self.logger, Some(counterparty_node_id), None, None), "Marking channels with {} disconnected and generating channel_updates.", log_pubkey!(counterparty_node_id) ); - if let Some(peer_state_mutex) = per_peer_state.get(counterparty_node_id) { + if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) { let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; let pending_msg_events = &mut peer_state.pending_msg_events; @@ -10475,7 +10650,7 @@ where } else { debug_assert!(false, "Unconnected peer disconnected"); true } }; if remove_peer { - per_peer_state.remove(counterparty_node_id); + per_peer_state.remove(&counterparty_node_id); } mem::drop(per_peer_state); @@ -10484,8 +10659,8 @@ where } } - fn peer_connected(&self, counterparty_node_id: &PublicKey, init_msg: &msgs::Init, inbound: bool) -> Result<(), ()> { - let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), None, None); + fn peer_connected(&self, counterparty_node_id: PublicKey, init_msg: &msgs::Init, inbound: bool) -> Result<(), ()> { + let logger = WithContext::from(&self.logger, Some(counterparty_node_id), None, None); if !init_msg.features.supports_static_remote_key() { log_debug!(logger, "Peer {} does not support static remote key, disconnecting", log_pubkey!(counterparty_node_id)); return Err(()); @@ -10542,7 +10717,7 @@ where log_debug!(logger, "Generating channel_reestablish events for {}", log_pubkey!(counterparty_node_id)); let per_peer_state = self.per_peer_state.read().unwrap(); - if let Some(peer_state_mutex) = per_peer_state.get(counterparty_node_id) { + if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) { let mut peer_state_lock = peer_state_mutex.lock().unwrap(); let peer_state = &mut *peer_state_lock; let pending_msg_events = &mut peer_state.pending_msg_events; @@ -10598,7 +10773,7 @@ where res } - fn handle_error(&self, counterparty_node_id: &PublicKey, msg: &msgs::ErrorMessage) { + fn handle_error(&self, counterparty_node_id: PublicKey, msg: &msgs::ErrorMessage) { match &msg.data as &str { "cannot co-op close channel w/ active htlcs"| "link failed to shutdown" => @@ -10615,18 +10790,18 @@ where self, || -> NotifyOption { let per_peer_state = self.per_peer_state.read().unwrap(); - let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id); + let peer_state_mutex_opt = per_peer_state.get(&counterparty_node_id); if peer_state_mutex_opt.is_none() { return NotifyOption::SkipPersistNoEvents; } let mut peer_state = peer_state_mutex_opt.unwrap().lock().unwrap(); if let Some(ChannelPhase::Funded(chan)) = peer_state.channel_by_id.get(&msg.channel_id) { if let Some(msg) = chan.get_outbound_shutdown() { peer_state.pending_msg_events.push(events::MessageSendEvent::SendShutdown { - node_id: *counterparty_node_id, + node_id: counterparty_node_id, msg, }); } peer_state.pending_msg_events.push(events::MessageSendEvent::HandleError { - node_id: *counterparty_node_id, + node_id: counterparty_node_id, action: msgs::ErrorAction::SendWarningMessage { msg: msgs::WarningMessage { channel_id: msg.channel_id, @@ -10653,7 +10828,7 @@ where if msg.channel_id.is_zero() { let channel_ids: Vec = { let per_peer_state = self.per_peer_state.read().unwrap(); - let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id); + let peer_state_mutex_opt = per_peer_state.get(&counterparty_node_id); if peer_state_mutex_opt.is_none() { return; } let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap(); let peer_state = &mut *peer_state_lock; @@ -10664,13 +10839,13 @@ where }; for channel_id in channel_ids { // Untrusted messages from peer, we throw away the error if id points to a non-existent channel - let _ = self.force_close_channel_with_peer(&channel_id, counterparty_node_id, Some(&msg.data), true); + let _ = self.force_close_channel_with_peer(&channel_id, &counterparty_node_id, Some(&msg.data), true); } } else { { // First check if we can advance the channel type and try again. let per_peer_state = self.per_peer_state.read().unwrap(); - let peer_state_mutex_opt = per_peer_state.get(counterparty_node_id); + let peer_state_mutex_opt = per_peer_state.get(&counterparty_node_id); if peer_state_mutex_opt.is_none() { return; } let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap(); let peer_state = &mut *peer_state_lock; @@ -10678,7 +10853,7 @@ where Some(ChannelPhase::UnfundedOutboundV1(ref mut chan)) => { if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) { peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannel { - node_id: *counterparty_node_id, + node_id: counterparty_node_id, msg, }); return; @@ -10688,7 +10863,7 @@ where Some(ChannelPhase::UnfundedOutboundV2(ref mut chan)) => { if let Ok(msg) = chan.maybe_handle_error_without_close(self.chain_hash, &self.fee_estimator) { peer_state.pending_msg_events.push(events::MessageSendEvent::SendOpenChannelV2 { - node_id: *counterparty_node_id, + node_id: counterparty_node_id, msg, }); return; @@ -10701,7 +10876,7 @@ where } // Untrusted messages from peer, we throw away the error if id points to a non-existent channel - let _ = self.force_close_channel_with_peer(&msg.channel_id, counterparty_node_id, Some(&msg.data), true); + let _ = self.force_close_channel_with_peer(&msg.channel_id, &counterparty_node_id, Some(&msg.data), true); } } @@ -10709,7 +10884,7 @@ where provided_node_features(&self.default_configuration) } - fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_init_features: PublicKey) -> InitFeatures { provided_init_features(&self.default_configuration) } @@ -10717,58 +10892,91 @@ where Some(vec![self.chain_hash]) } - fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) { + 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); + msg.channel_id.clone())), counterparty_node_id); } - fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) { + 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); + msg.channel_id.clone())), counterparty_node_id); + } + + fn message_received(&self) { + for (payment_id, retryable_invoice_request) in self + .pending_outbound_payments + .release_invoice_requests_awaiting_invoice() + { + let RetryableInvoiceRequest { invoice_request, nonce } = retryable_invoice_request; + let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key); + let context = MessageContext::Offers(OffersContext::OutboundPayment { + payment_id, + nonce, + hmac: Some(hmac) + }); + match self.create_blinded_paths(context, BlindedPathType::Full) { + Ok(reply_paths) => match self.enqueue_invoice_request(invoice_request, reply_paths) { + Ok(_) => {} + Err(_) => { + log_warn!(self.logger, + "Retry failed for an invoice request with payment_id: {}", + payment_id + ); + } + }, + Err(_) => { + log_warn!(self.logger, + "Retry failed for an invoice request with payment_id: {}. \ + Reason: router could not find a blinded path to include as the reply path", + payment_id + ); + } + } + } } } @@ -10790,6 +10998,41 @@ where let secp_ctx = &self.secp_ctx; let expanded_key = &self.inbound_payment_key; + macro_rules! handle_pay_invoice_res { + ($res: expr, $invoice: expr, $logger: expr) => {{ + let error = match $res { + Err(Bolt12PaymentError::UnknownRequiredFeatures) => { + log_trace!( + $logger, "Invoice requires unknown features: {:?}", + $invoice.invoice_features() + ); + InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures) + }, + Err(Bolt12PaymentError::SendingFailed(e)) => { + log_trace!($logger, "Failed paying invoice: {:?}", e); + InvoiceError::from_string(format!("{:?}", e)) + }, + #[cfg(async_payments)] + Err(Bolt12PaymentError::BlindedPathCreationFailed) => { + let err_msg = "Failed to create a blinded path back to ourselves"; + log_trace!($logger, "{}", err_msg); + InvoiceError::from_string(err_msg.to_string()) + }, + Err(Bolt12PaymentError::UnexpectedInvoice) + | Err(Bolt12PaymentError::DuplicateInvoice) + | Ok(()) => return None, + }; + + match responder { + Some(responder) => return Some((OffersMessage::InvoiceError(error), responder.respond())), + None => { + log_trace!($logger, "No reply path to send error: {:?}", error); + return None + }, + } + }} + } + match message { OffersMessage::InvoiceRequest(invoice_request) => { let responder = match responder { @@ -10889,7 +11132,12 @@ where }; match response { - Ok(invoice) => Some((OffersMessage::Invoice(invoice), responder.respond())), + Ok(invoice) => { + let nonce = Nonce::from_entropy_source(&*self.entropy_source); + let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key); + let context = MessageContext::Offers(OffersContext::InboundPayment { payment_hash, nonce, hmac }); + Some((OffersMessage::Invoice(invoice), responder.respond_with_reply_path(context))) + }, Err(error) => Some((OffersMessage::InvoiceError(error.into()), responder.respond())), } }, @@ -10911,47 +11159,31 @@ where return None; } - let error = match self.send_payment_for_verified_bolt12_invoice( - &invoice, payment_id, - ) { - Err(Bolt12PaymentError::UnknownRequiredFeatures) => { - log_trace!( - logger, "Invoice requires unknown features: {:?}", - invoice.invoice_features() - ); - InvoiceError::from(Bolt12SemanticError::UnknownRequiredFeatures) - }, - Err(Bolt12PaymentError::SendingFailed(e)) => { - log_trace!(logger, "Failed paying invoice: {:?}", e); - InvoiceError::from_string(format!("{:?}", e)) - }, - Err(Bolt12PaymentError::UnexpectedInvoice) - | Err(Bolt12PaymentError::DuplicateInvoice) - | Ok(()) => return None, - }; - - match responder { - Some(responder) => Some((OffersMessage::InvoiceError(error), responder.respond())), - None => { - log_trace!(logger, "No reply path to send error: {:?}", error); - None - }, - } + let res = self.send_payment_for_verified_bolt12_invoice(&invoice, payment_id); + handle_pay_invoice_res!(res, invoice, logger); }, #[cfg(async_payments)] - OffersMessage::StaticInvoice(_invoice) => { - match responder { - Some(responder) => { - return Some((OffersMessage::InvoiceError( - InvoiceError::from_string("Static invoices not yet supported".to_string()) - ), responder.respond())); + OffersMessage::StaticInvoice(invoice) => { + let payment_id = match context { + Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => { + if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() { + return None + } + payment_id }, - None => return None, - } + _ => return None + }; + let res = self.initiate_async_payment(&invoice, payment_id); + handle_pay_invoice_res!(res, invoice, self.logger); }, OffersMessage::InvoiceError(invoice_error) => { let payment_hash = match context { - Some(OffersContext::InboundPayment { payment_hash }) => Some(payment_hash), + Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => { + match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) { + Ok(_) => Some(payment_hash), + Err(_) => None, + } + }, _ => None, }; @@ -10960,7 +11192,7 @@ where match context { Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => { - if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) { + if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) { self.abandon_payment_with_reason( payment_id, PaymentFailureReason::InvoiceRequestRejected, ); @@ -10997,10 +11229,20 @@ where None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) { + #[cfg(async_payments)] { + let AsyncPaymentsContext::OutboundPayment { payment_id, hmac, nonce } = _context; + if payment_id.verify_for_async_payment(hmac, nonce, &self.inbound_payment_key).is_err() { return } + if let Err(e) = self.send_payment_for_static_invoice(payment_id) { + log_trace!( + self.logger, "Failed to release held HTLC with payment id {}: {:?}", payment_id, e + ); + } + } + } fn release_pending_messages(&self) -> Vec<(AsyncPaymentsMessage, MessageSendInstructions)> { - Vec::new() + core::mem::take(&mut self.pending_async_payments_messages.lock().unwrap()) } } @@ -11621,6 +11863,7 @@ where } PendingOutboundPayment::AwaitingInvoice { .. } => {}, PendingOutboundPayment::InvoiceReceived { .. } => {}, + PendingOutboundPayment::StaticInvoiceReceived { .. } => {}, PendingOutboundPayment::Fulfilled { .. } => {}, PendingOutboundPayment::Abandoned { .. } => {}, } @@ -12176,10 +12419,7 @@ where } pending_outbound_payments = Some(outbounds); } - let pending_outbounds = OutboundPayments { - pending_outbound_payments: Mutex::new(pending_outbound_payments.unwrap()), - retry_lock: Mutex::new(()) - }; + let pending_outbounds = OutboundPayments::new(pending_outbound_payments.unwrap()); // We have to replay (or skip, if they were completed after we wrote the `ChannelManager`) // each `ChannelMonitorUpdate` in `in_flight_monitor_updates`. After doing so, we have to @@ -12326,37 +12566,11 @@ where return Err(DecodeError::InvalidValue); } - let path_amt = path.final_value_msat(); let mut session_priv_bytes = [0; 32]; session_priv_bytes[..].copy_from_slice(&session_priv[..]); - match pending_outbounds.pending_outbound_payments.lock().unwrap().entry(payment_id) { - hash_map::Entry::Occupied(mut entry) => { - let newly_added = entry.get_mut().insert(session_priv_bytes, &path); - log_info!(logger, "{} a pending payment path for {} msat for session priv {} on an existing pending payment with payment hash {}", - if newly_added { "Added" } else { "Had" }, path_amt, log_bytes!(session_priv_bytes), htlc.payment_hash); - }, - hash_map::Entry::Vacant(entry) => { - let path_fee = path.fee_msat(); - entry.insert(PendingOutboundPayment::Retryable { - retry_strategy: None, - attempts: PaymentAttempts::new(), - payment_params: None, - session_privs: hash_set_from_iter([session_priv_bytes]), - payment_hash: htlc.payment_hash, - payment_secret: None, // only used for retries, and we'll never retry on startup - payment_metadata: None, // only used for retries, and we'll never retry on startup - keysend_preimage: None, // only used for retries, and we'll never retry on startup - custom_tlvs: Vec::new(), // only used for retries, and we'll never retry on startup - pending_amt_msat: path_amt, - pending_fee_msat: Some(path_fee), - total_msat: path_amt, - starting_block_height: best_block_height, - remaining_max_total_routing_fee_msat: None, // only used for retries, and we'll never retry on startup - }); - log_info!(logger, "Added a pending payment for {} msat with payment hash {} for path with session priv {}", - path_amt, &htlc.payment_hash, log_bytes!(session_priv_bytes)); - } - } + pending_outbounds.insert_from_monitor_on_startup( + payment_id, htlc.payment_hash, session_priv_bytes, &path, best_block_height, logger + ); } } for (htlc_source, (htlc, preimage_opt)) in monitor.get_all_current_outbound_htlcs() { @@ -12733,6 +12947,7 @@ where funding_batch_states: Mutex::new(BTreeMap::new()), pending_offers_messages: Mutex::new(Vec::new()), + pending_async_payments_messages: Mutex::new(Vec::new()), pending_broadcast_messages: Mutex::new(Vec::new()), @@ -12827,16 +13042,16 @@ mod tests { // Node 3, unrelated to the only channel, shouldn't care if it receives a channel_update // about the channel. - nodes[2].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan.0); - nodes[2].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan.1); + nodes[2].node.handle_channel_update(nodes[1].node.get_our_node_id(), &chan.0); + nodes[2].node.handle_channel_update(nodes[1].node.get_our_node_id(), &chan.1); assert!(!nodes[2].node.get_event_or_persistence_needed_future().poll_is_complete()); // The nodes which are a party to the channel should also ignore messages from unrelated // parties. - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.0); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.1); - nodes[1].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.0); - nodes[1].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.1); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan.0); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan.1); + nodes[1].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan.0); + nodes[1].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan.1); assert!(!nodes[0].node.get_event_or_persistence_needed_future().poll_is_complete()); assert!(!nodes[1].node.get_event_or_persistence_needed_future().poll_is_complete()); @@ -12853,8 +13068,8 @@ mod tests { // First deliver each peers' own message, checking that the node doesn't need to be // persisted and that its channel info remains the same. - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &as_update); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &bs_update); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &as_update); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &bs_update); assert!(!nodes[0].node.get_event_or_persistence_needed_future().poll_is_complete()); assert!(!nodes[1].node.get_event_or_persistence_needed_future().poll_is_complete()); assert_eq!(nodes[0].node.list_channels()[0], node_a_chan_info); @@ -12862,8 +13077,8 @@ mod tests { // Finally, deliver the other peers' message, ensuring each node needs to be persisted and // the channel info has updated. - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &bs_update); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &as_update); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &bs_update); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &as_update); assert!(nodes[0].node.get_event_or_persistence_needed_future().poll_is_complete()); assert!(nodes[1].node.get_event_or_persistence_needed_future().poll_is_complete()); assert_ne!(nodes[0].node.list_channels()[0], node_a_chan_info); @@ -12906,7 +13121,7 @@ mod tests { assert_eq!(events.len(), 1); let ev = events.drain(..).next().unwrap(); let payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -12918,7 +13133,7 @@ mod tests { assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true); expect_payment_failed!(nodes[0], our_payment_hash, true); @@ -12939,30 +13154,30 @@ mod tests { check_added_monitors!(nodes[1], 2); let bs_first_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_first_raa, as_first_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); check_added_monitors!(nodes[1], 1); let bs_second_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_first_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_first_cs); check_added_monitors!(nodes[1], 1); let bs_first_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed); check_added_monitors!(nodes[0], 1); let as_second_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); let as_second_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_second_updates.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_third_raa); check_added_monitors!(nodes[0], 1); // Note that successful MPP payments will generate a single PaymentSent event upon the first @@ -13033,7 +13248,7 @@ mod tests { assert_eq!(events.len(), 1); let ev = events.drain(..).next().unwrap(); let payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // We have to forward pending HTLCs twice - once tries to forward the payment forward (and @@ -13047,7 +13262,7 @@ mod tests { assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true); expect_payment_failed!(nodes[0], payment_hash, true); @@ -13078,7 +13293,7 @@ mod tests { assert_eq!(events.len(), 1); let ev = events.drain(..).next().unwrap(); let payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -13090,7 +13305,7 @@ mod tests { assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true); expect_payment_failed!(nodes[0], payment_hash, true); @@ -13125,7 +13340,7 @@ mod tests { assert_eq!(events.len(), 1); let ev = events.drain(..).next().unwrap(); let payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -13137,7 +13352,7 @@ mod tests { assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true); expect_payment_failed!(nodes[0], payment_hash, true); @@ -13183,7 +13398,7 @@ mod tests { assert!(updates.update_fail_htlcs.is_empty()); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Payment preimage didn't match payment hash", 1); } @@ -13230,7 +13445,7 @@ mod tests { assert!(updates.update_fail_htlcs.is_empty()); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "We don't support MPP keysend payments", 1); } @@ -13292,20 +13507,20 @@ mod tests { } // Test that we do not retrieve the pending broadcast messages when we are not connected to any peer - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[0].node.get_our_node_id()); let node_0_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(node_0_events.len(), 0); // Now we reconnect to a peer - nodes[0].node.peer_connected(&nodes[2].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[2].node.get_our_node_id(), &msgs::Init { features: nodes[2].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[2].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[2].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); @@ -13332,8 +13547,8 @@ mod tests { let chan = create_announced_chan_between_nodes(&nodes, 0, 1); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let error_message = "Channel force-closed"; nodes[0].node.force_close_broadcasting_latest_txn(&chan.2, &nodes[1].node.get_our_node_id(), error_message.to_string()).unwrap(); check_closed_broadcast!(nodes[0], true); @@ -13398,9 +13613,9 @@ mod tests { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42); let channel_id = ChannelId::from_bytes(tx.compute_txid().to_byte_array()); @@ -13424,7 +13639,7 @@ mod tests { let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); { let nodes_0_lock = nodes[0].node.outpoint_to_peer.lock().unwrap(); assert_eq!(nodes_0_lock.len(), 1); @@ -13441,7 +13656,7 @@ mod tests { } check_added_monitors!(nodes[1], 1); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx); @@ -13449,12 +13664,12 @@ mod tests { update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &nodes_0_update, &nodes_1_update); nodes[0].node.close_channel(&channel_id, &nodes[1].node.get_our_node_id()).unwrap(); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id())); let nodes_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &nodes_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &nodes_1_shutdown); let closing_signed_node_0 = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &closing_signed_node_0); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &closing_signed_node_0); { // Assert that the channel is kept in the `outpoint_to_peer` map for both nodes until the // channel can be fully closed by both parties (i.e. no outstanding htlcs exists, the @@ -13475,7 +13690,7 @@ mod tests { assert!(nodes_1_lock.contains_key(&funding_output)); } - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id())); { // `nodes[0]` accepts `nodes[1]`'s proposed fee for the closing transaction, and // therefore has all it needs to fully close the channel (both signatures for the @@ -13493,7 +13708,7 @@ mod tests { let (_nodes_0_update, closing_signed_node_0) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &closing_signed_node_0.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &closing_signed_node_0.unwrap()); { // Assert that the channel has now been removed from both parties `outpoint_to_peer` map once // they both have everything required to fully close the channel. @@ -13616,23 +13831,23 @@ mod tests { let mut funding_tx = None; for idx in 0..super::MAX_UNFUNDED_CHANS_PER_PEER { - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); if idx == 0 { - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42); funding_tx = Some(tx.clone()); nodes[0].node.funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), tx).unwrap(); let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); } @@ -13642,7 +13857,7 @@ mod tests { // A MAX_UNFUNDED_CHANS_PER_PEER + 1 channel will be summarily rejected open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source( &nodes[0].keys_manager); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.common_fields.temporary_channel_id); @@ -13654,47 +13869,47 @@ mod tests { let random_pk = PublicKey::from_secret_key(&nodes[0].node.secp_ctx, &SecretKey::from_slice(&nodes[1].keys_manager.get_secure_random_bytes()).unwrap()); peer_pks.push(random_pk); - nodes[1].node.peer_connected(&random_pk, &msgs::Init { + nodes[1].node.peer_connected(random_pk, &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); } let last_random_pk = PublicKey::from_secret_key(&nodes[0].node.secp_ctx, &SecretKey::from_slice(&nodes[1].keys_manager.get_secure_random_bytes()).unwrap()); - nodes[1].node.peer_connected(&last_random_pk, &msgs::Init { + nodes[1].node.peer_connected(last_random_pk, &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap_err(); // Also importantly, because nodes[0] isn't "protected", we will refuse a reconnection from // them if we have too many un-channel'd peers. - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let chan_closed_events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(chan_closed_events.len(), super::MAX_UNFUNDED_CHANS_PER_PEER - 1); for ev in chan_closed_events { if let Event::ChannelClosed { .. } = ev { } else { panic!(); } } - nodes[1].node.peer_connected(&last_random_pk, &msgs::Init { + nodes[1].node.peer_connected(last_random_pk, &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap_err(); // but of course if the connection is outbound its allowed... - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Now nodes[0] is disconnected but still has a pending, un-funded channel lying around. // Even though we accept one more connection from new peers, we won't actually let them // open channels. assert!(peer_pks.len() > super::MAX_UNFUNDED_CHANNEL_PEERS - 1); for i in 0..super::MAX_UNFUNDED_CHANNEL_PEERS - 1 { - nodes[1].node.handle_open_channel(&peer_pks[i], &open_channel_msg); + nodes[1].node.handle_open_channel(peer_pks[i], &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, peer_pks[i]); open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source(&nodes[0].keys_manager); } - nodes[1].node.handle_open_channel(&last_random_pk, &open_channel_msg); + nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); assert_eq!(get_err_msg(&nodes[1], &last_random_pk).channel_id, open_channel_msg.common_fields.temporary_channel_id); @@ -13705,14 +13920,14 @@ mod tests { // If we fund the first channel, nodes[0] has a live on-chain channel with us, it is now // "protected" and can connect again. mine_transaction(&nodes[1], funding_tx.as_ref().unwrap()); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); get_event_msg!(nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id()); // Further, because the first channel was funded, we can open another channel with // last_random_pk. - nodes[1].node.handle_open_channel(&last_random_pk, &open_channel_msg); + nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, last_random_pk); } @@ -13730,14 +13945,14 @@ mod tests { let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); for _ in 0..super::MAX_UNFUNDED_CHANS_PER_PEER { - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); open_channel_msg.common_fields.temporary_channel_id = ChannelId::temporary_from_entropy_source(&nodes[0].keys_manager); } // Once we have MAX_UNFUNDED_CHANS_PER_PEER unfunded channels, new inbound channels will be // rejected. - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.common_fields.temporary_channel_id); @@ -13746,7 +13961,7 @@ mod tests { get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); // but even with such an outbound channel, additional inbound channels will still fail. - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); assert_eq!(get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()).channel_id, open_channel_msg.common_fields.temporary_channel_id); } @@ -13771,11 +13986,11 @@ mod tests { for _ in 0..super::MAX_UNFUNDED_CHANNEL_PEERS - 1 { let random_pk = PublicKey::from_secret_key(&nodes[0].node.secp_ctx, &SecretKey::from_slice(&nodes[1].keys_manager.get_secure_random_bytes()).unwrap()); - nodes[1].node.peer_connected(&random_pk, &msgs::Init { + nodes[1].node.peer_connected(random_pk, &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.handle_open_channel(&random_pk, &open_channel_msg); + nodes[1].node.handle_open_channel(random_pk, &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -13790,10 +14005,10 @@ mod tests { // If we try to accept a channel from another peer non-0conf it will fail. let last_random_pk = PublicKey::from_secret_key(&nodes[0].node.secp_ctx, &SecretKey::from_slice(&nodes[1].keys_manager.get_secure_random_bytes()).unwrap()); - nodes[1].node.peer_connected(&last_random_pk, &msgs::Init { + nodes[1].node.peer_connected(last_random_pk, &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.handle_open_channel(&last_random_pk, &open_channel_msg); + nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -13809,7 +14024,7 @@ mod tests { open_channel_msg.common_fields.temporary_channel_id); // ...however if we accept the same channel 0conf it should work just fine. - nodes[1].node.handle_open_channel(&last_random_pk, &open_channel_msg); + nodes[1].node.handle_open_channel(last_random_pk, &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -13911,7 +14126,7 @@ mod tests { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); match &msg_events[0] { @@ -13926,7 +14141,7 @@ mod tests { _ => panic!("Unexpected event"), } - nodes[2].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[2].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let events = nodes[2].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => @@ -13954,7 +14169,7 @@ mod tests { let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert!(open_channel_msg.common_fields.channel_type.as_ref().unwrap().supports_anchors_zero_fee_htlc_tx()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -13964,7 +14179,7 @@ mod tests { } let error_msg = get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &error_msg); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &error_msg); let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert!(!open_channel_msg.common_fields.channel_type.unwrap().supports_anchors_zero_fee_htlc_tx()); @@ -14070,8 +14285,8 @@ mod tests { // Open a channel, immediately disconnect each other, and broadcast Alice's latest state. let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); nodes[0].node.force_close_broadcasting_latest_txn(&chan_id, &nodes[1].node.get_our_node_id(), error_message.to_string()).unwrap(); check_closed_broadcast(&nodes[0], 1, true); check_added_monitors(&nodes[0], 1); @@ -14085,17 +14300,17 @@ mod tests { // Since they're disconnected, Bob won't receive Alice's `Error` message. Reconnect them // such that Bob sends a `ChannelReestablish` to Alice since the channel is still open from // their side. - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); let channel_reestablish = get_event_msg!( nodes[1], MessageSendEvent::SendChannelReestablish, nodes[0].node.get_our_node_id() ); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &channel_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &channel_reestablish); // Alice should respond with an error since the channel isn't known, but a bogus // `ChannelReestablish` should be sent first, such that we actually trigger Bob to force @@ -14106,7 +14321,7 @@ mod tests { assert_eq!(*node_id, nodes[1].node.get_our_node_id()); assert_eq!(msg.next_local_commitment_number, 0); assert_eq!(msg.next_remote_commitment_number, 0); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &msg); } else { panic!() }; check_closed_broadcast(&nodes[1], 1, true); check_added_monitors(&nodes[1], 1); @@ -14263,15 +14478,15 @@ pub mod bench { }, genesis_block.header.time); let node_b_holder = ANodeHolder { node: &node_b }; - node_a.peer_connected(&node_b.get_our_node_id(), &Init { + node_a.peer_connected(node_b.get_our_node_id(), &Init { features: node_b.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - node_b.peer_connected(&node_a.get_our_node_id(), &Init { + node_b.peer_connected(node_a.get_our_node_id(), &Init { features: node_a.init_features(), networks: None, remote_network_address: None }, false).unwrap(); node_a.create_channel(node_b.get_our_node_id(), 8_000_000, 100_000_000, 42, None, None).unwrap(); - node_b.handle_open_channel(&node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendOpenChannel, node_b.get_our_node_id())); - node_a.handle_accept_channel(&node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendAcceptChannel, node_a.get_our_node_id())); + node_b.handle_open_channel(node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendOpenChannel, node_b.get_our_node_id())); + node_a.handle_accept_channel(node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendAcceptChannel, node_a.get_our_node_id())); let tx; if let Event::FundingGenerationReady { temporary_channel_id, output_script, .. } = get_event!(node_a_holder, Event::FundingGenerationReady) { @@ -14281,7 +14496,7 @@ pub mod bench { node_a.funding_transaction_generated(temporary_channel_id, node_b.get_our_node_id(), tx.clone()).unwrap(); } else { panic!(); } - node_b.handle_funding_created(&node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendFundingCreated, node_b.get_our_node_id())); + node_b.handle_funding_created(node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendFundingCreated, node_b.get_our_node_id())); let events_b = node_b.get_and_clear_pending_events(); assert_eq!(events_b.len(), 1); match events_b[0] { @@ -14291,7 +14506,7 @@ pub mod bench { _ => panic!("Unexpected event"), } - node_a.handle_funding_signed(&node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendFundingSigned, node_a.get_our_node_id())); + node_a.handle_funding_signed(node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendFundingSigned, node_a.get_our_node_id())); let events_a = node_a.get_and_clear_pending_events(); assert_eq!(events_a.len(), 1); match events_a[0] { @@ -14307,12 +14522,12 @@ pub mod bench { Listen::block_connected(&node_a, &block, 1); Listen::block_connected(&node_b, &block, 1); - node_a.handle_channel_ready(&node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendChannelReady, node_a.get_our_node_id())); + node_a.handle_channel_ready(node_b.get_our_node_id(), &get_event_msg!(node_b_holder, MessageSendEvent::SendChannelReady, node_a.get_our_node_id())); let msg_events = node_a.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 2); match msg_events[0] { MessageSendEvent::SendChannelReady { ref msg, .. } => { - node_b.handle_channel_ready(&node_a.get_our_node_id(), msg); + node_b.handle_channel_ready(node_a.get_our_node_id(), msg); get_event_msg!(node_b_holder, MessageSendEvent::SendChannelUpdate, node_a.get_our_node_id()); }, _ => panic!(), @@ -14356,12 +14571,12 @@ pub mod bench { RouteParameters::from_payment_params_and_value(payment_params, 10_000), Retry::Attempts(0)).unwrap(); let payment_event = SendEvent::from_event($node_a.get_and_clear_pending_msg_events().pop().unwrap()); - $node_b.handle_update_add_htlc(&$node_a.get_our_node_id(), &payment_event.msgs[0]); - $node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &payment_event.commitment_msg); + $node_b.handle_update_add_htlc($node_a.get_our_node_id(), &payment_event.msgs[0]); + $node_b.handle_commitment_signed($node_a.get_our_node_id(), &payment_event.commitment_msg); let (raa, cs) = get_revoke_commit_msgs(&ANodeHolder { node: &$node_b }, &$node_a.get_our_node_id()); - $node_a.handle_revoke_and_ack(&$node_b.get_our_node_id(), &raa); - $node_a.handle_commitment_signed(&$node_b.get_our_node_id(), &cs); - $node_b.handle_revoke_and_ack(&$node_a.get_our_node_id(), &get_event_msg!(ANodeHolder { node: &$node_a }, MessageSendEvent::SendRevokeAndACK, $node_b.get_our_node_id())); + $node_a.handle_revoke_and_ack($node_b.get_our_node_id(), &raa); + $node_a.handle_commitment_signed($node_b.get_our_node_id(), &cs); + $node_b.handle_revoke_and_ack($node_a.get_our_node_id(), &get_event_msg!(ANodeHolder { node: &$node_a }, MessageSendEvent::SendRevokeAndACK, $node_b.get_our_node_id())); expect_pending_htlcs_forwardable!(ANodeHolder { node: &$node_b }); expect_payment_claimable!(ANodeHolder { node: &$node_b }, payment_hash, payment_secret, 10_000); @@ -14371,16 +14586,16 @@ pub mod bench { match $node_b.get_and_clear_pending_msg_events().pop().unwrap() { MessageSendEvent::UpdateHTLCs { node_id, updates } => { assert_eq!(node_id, $node_a.get_our_node_id()); - $node_a.handle_update_fulfill_htlc(&$node_b.get_our_node_id(), &updates.update_fulfill_htlcs[0]); - $node_a.handle_commitment_signed(&$node_b.get_our_node_id(), &updates.commitment_signed); + $node_a.handle_update_fulfill_htlc($node_b.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + $node_a.handle_commitment_signed($node_b.get_our_node_id(), &updates.commitment_signed); }, _ => panic!("Failed to generate claim event"), } let (raa, cs) = get_revoke_commit_msgs(&ANodeHolder { node: &$node_a }, &$node_b.get_our_node_id()); - $node_b.handle_revoke_and_ack(&$node_a.get_our_node_id(), &raa); - $node_b.handle_commitment_signed(&$node_a.get_our_node_id(), &cs); - $node_a.handle_revoke_and_ack(&$node_b.get_our_node_id(), &get_event_msg!(ANodeHolder { node: &$node_b }, MessageSendEvent::SendRevokeAndACK, $node_a.get_our_node_id())); + $node_b.handle_revoke_and_ack($node_a.get_our_node_id(), &raa); + $node_b.handle_commitment_signed($node_a.get_our_node_id(), &cs); + $node_a.handle_revoke_and_ack($node_b.get_our_node_id(), &get_event_msg!(ANodeHolder { node: &$node_b }, MessageSendEvent::SendRevokeAndACK, $node_a.get_our_node_id())); expect_payment_sent!(ANodeHolder { node: &$node_a }, payment_preimage); } diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index f3290bf1583..1c5af0d8f06 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -456,7 +456,7 @@ pub struct Node<'chan_man, 'node_cfg: 'chan_man, 'chan_mon_cfg: 'node_cfg> { } impl<'a, 'b, 'c> Node<'a, 'b, 'c> { - pub fn init_features(&self, peer_node_id: &PublicKey) -> InitFeatures { + pub fn init_features(&self, peer_node_id: PublicKey) -> InitFeatures { self.override_init_features.borrow().clone() .unwrap_or_else(|| self.node.init_features() | self.onion_messenger.provided_init_features(peer_node_id)) } @@ -1144,8 +1144,8 @@ macro_rules! reload_node { ($node: expr, $new_config: expr, $chanman_encoded: expr, $monitors_encoded: expr, $persister: ident, $new_chain_monitor: ident, $new_channelmanager: ident) => { let chanman_encoded = $chanman_encoded; - $persister = test_utils::TestPersister::new(); - $new_chain_monitor = test_utils::TestChainMonitor::new(Some($node.chain_source), $node.tx_broadcaster.clone(), $node.logger, $node.fee_estimator, &$persister, &$node.keys_manager); + $persister = $crate::util::test_utils::TestPersister::new(); + $new_chain_monitor = $crate::util::test_utils::TestChainMonitor::new(Some($node.chain_source), $node.tx_broadcaster.clone(), $node.logger, $node.fee_estimator, &$persister, &$node.keys_manager); $node.chain_monitor = &$new_chain_monitor; $new_channelmanager = _reload_node(&$node, $new_config, &chanman_encoded, $monitors_encoded); @@ -1212,7 +1212,7 @@ pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: & let funding_created_msg = get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id()); assert_eq!(funding_created_msg.temporary_channel_id, expected_temporary_channel_id); - node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &funding_created_msg); + node_b.node.handle_funding_created(node_a.node.get_our_node_id(), &funding_created_msg); { let mut added_monitors = node_b.chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -1221,7 +1221,7 @@ pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: & } expect_channel_pending_event(&node_b, &node_a.node.get_our_node_id()); - node_a.node.handle_funding_signed(&node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendFundingSigned, node_a.node.get_our_node_id())); + node_a.node.handle_funding_signed(node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendFundingSigned, node_a.node.get_our_node_id())); { let mut added_monitors = node_a.chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -1253,7 +1253,7 @@ pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>(initiator: &'a Node<'b, 'c, 'd>, r initiator.node.create_channel(receiver.node.get_our_node_id(), 100_000, 10_001, 42, None, initiator_config).unwrap(); let open_channel = get_event_msg!(initiator, MessageSendEvent::SendOpenChannel, receiver.node.get_our_node_id()); - receiver.node.handle_open_channel(&initiator.node.get_our_node_id(), &open_channel); + receiver.node.handle_open_channel(initiator.node.get_our_node_id(), &open_channel); let events = receiver.node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { @@ -1265,13 +1265,13 @@ pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>(initiator: &'a Node<'b, 'c, 'd>, r let accept_channel = get_event_msg!(receiver, MessageSendEvent::SendAcceptChannel, initiator.node.get_our_node_id()); assert_eq!(accept_channel.common_fields.minimum_depth, 0); - initiator.node.handle_accept_channel(&receiver.node.get_our_node_id(), &accept_channel); + initiator.node.handle_accept_channel(receiver.node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, _) = create_funding_transaction(&initiator, &receiver.node.get_our_node_id(), 100_000, 42); initiator.node.funding_transaction_generated(temporary_channel_id, receiver.node.get_our_node_id(), tx.clone()).unwrap(); let funding_created = get_event_msg!(initiator, MessageSendEvent::SendFundingCreated, receiver.node.get_our_node_id()); - receiver.node.handle_funding_created(&initiator.node.get_our_node_id(), &funding_created); + receiver.node.handle_funding_created(initiator.node.get_our_node_id(), &funding_created); check_added_monitors!(receiver, 1); let bs_signed_locked = receiver.node.get_and_clear_pending_msg_events(); assert_eq!(bs_signed_locked.len(), 2); @@ -1279,7 +1279,7 @@ pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>(initiator: &'a Node<'b, 'c, 'd>, r match &bs_signed_locked[0] { MessageSendEvent::SendFundingSigned { node_id, msg } => { assert_eq!(*node_id, initiator.node.get_our_node_id()); - initiator.node.handle_funding_signed(&receiver.node.get_our_node_id(), &msg); + initiator.node.handle_funding_signed(receiver.node.get_our_node_id(), &msg); expect_channel_pending_event(&initiator, &receiver.node.get_our_node_id()); expect_channel_pending_event(&receiver, &initiator.node.get_our_node_id()); check_added_monitors!(initiator, 1); @@ -1294,20 +1294,20 @@ pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>(initiator: &'a Node<'b, 'c, 'd>, r match &bs_signed_locked[1] { MessageSendEvent::SendChannelReady { node_id, msg } => { assert_eq!(*node_id, initiator.node.get_our_node_id()); - initiator.node.handle_channel_ready(&receiver.node.get_our_node_id(), &msg); + initiator.node.handle_channel_ready(receiver.node.get_our_node_id(), &msg); expect_channel_ready_event(&initiator, &receiver.node.get_our_node_id()); } _ => panic!("Unexpected event"), } - receiver.node.handle_channel_ready(&initiator.node.get_our_node_id(), &as_channel_ready); + receiver.node.handle_channel_ready(initiator.node.get_our_node_id(), &as_channel_ready); expect_channel_ready_event(&receiver, &initiator.node.get_our_node_id()); let as_channel_update = get_event_msg!(initiator, MessageSendEvent::SendChannelUpdate, receiver.node.get_our_node_id()); let bs_channel_update = get_event_msg!(receiver, MessageSendEvent::SendChannelUpdate, initiator.node.get_our_node_id()); - initiator.node.handle_channel_update(&receiver.node.get_our_node_id(), &bs_channel_update); - receiver.node.handle_channel_update(&initiator.node.get_our_node_id(), &as_channel_update); + initiator.node.handle_channel_update(receiver.node.get_our_node_id(), &bs_channel_update); + receiver.node.handle_channel_update(initiator.node.get_our_node_id(), &as_channel_update); assert_eq!(initiator.node.list_usable_channels().len(), initiator_channels + 1); assert_eq!(receiver.node.list_usable_channels().len(), receiver_channels + 1); @@ -1320,7 +1320,7 @@ pub fn exchange_open_accept_chan<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: let open_channel_msg = get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id()); assert_eq!(open_channel_msg.common_fields.temporary_channel_id, create_chan_id); assert_eq!(node_a.node.list_channels().iter().find(|channel| channel.channel_id == create_chan_id).unwrap().user_channel_id, 42); - node_b.node.handle_open_channel(&node_a.node.get_our_node_id(), &open_channel_msg); + node_b.node.handle_open_channel(node_a.node.get_our_node_id(), &open_channel_msg); if node_b.node.get_current_default_configuration().manually_accept_inbound_channels { let events = node_b.node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -1332,7 +1332,7 @@ pub fn exchange_open_accept_chan<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: } let accept_channel_msg = get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id()); assert_eq!(accept_channel_msg.common_fields.temporary_channel_id, create_chan_id); - node_a.node.handle_accept_channel(&node_b.node.get_our_node_id(), &accept_channel_msg); + node_a.node.handle_accept_channel(node_b.node.get_our_node_id(), &accept_channel_msg); assert_ne!(node_b.node.list_channels().iter().find(|channel| channel.channel_id == create_chan_id).unwrap().user_channel_id, 0); create_chan_id @@ -1346,7 +1346,7 @@ pub fn create_chan_between_nodes_with_value_init<'a, 'b, 'c>(node_a: &Node<'a, ' pub fn create_chan_between_nodes_with_value_confirm_first<'a, 'b, 'c, 'd>(node_recv: &'a Node<'b, 'c, 'c>, node_conf: &'a Node<'b, 'c, 'd>, tx: &Transaction, conf_height: u32) { confirm_transaction_at(node_conf, tx, conf_height); connect_blocks(node_conf, CHAN_CONFIRM_DEPTH - 1); - node_recv.node.handle_channel_ready(&node_conf.node.get_our_node_id(), &get_event_msg!(node_conf, MessageSendEvent::SendChannelReady, node_recv.node.get_our_node_id())); + node_recv.node.handle_channel_ready(node_conf.node.get_our_node_id(), &get_event_msg!(node_conf, MessageSendEvent::SendChannelReady, node_recv.node.get_our_node_id())); } pub fn create_chan_between_nodes_with_value_confirm_second<'a, 'b, 'c>(node_recv: &Node<'a, 'b, 'c>, node_conf: &Node<'a, 'b, 'c>) -> ((msgs::ChannelReady, msgs::AnnouncementSignatures), ChannelId) { @@ -1392,9 +1392,9 @@ pub fn create_chan_between_nodes_with_value_a<'a, 'b, 'c: 'd, 'd>(node_a: &'a No } pub fn create_chan_between_nodes_with_value_b<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, as_funding_msgs: &(msgs::ChannelReady, msgs::AnnouncementSignatures)) -> (msgs::ChannelAnnouncement, msgs::ChannelUpdate, msgs::ChannelUpdate) { - node_b.node.handle_channel_ready(&node_a.node.get_our_node_id(), &as_funding_msgs.0); + node_b.node.handle_channel_ready(node_a.node.get_our_node_id(), &as_funding_msgs.0); let bs_announcement_sigs = get_event_msg!(node_b, MessageSendEvent::SendAnnouncementSignatures, node_a.node.get_our_node_id()); - node_b.node.handle_announcement_signatures(&node_a.node.get_our_node_id(), &as_funding_msgs.1); + node_b.node.handle_announcement_signatures(node_a.node.get_our_node_id(), &as_funding_msgs.1); let events_7 = node_b.node.get_and_clear_pending_msg_events(); assert_eq!(events_7.len(), 1); @@ -1405,7 +1405,7 @@ pub fn create_chan_between_nodes_with_value_b<'a, 'b, 'c>(node_a: &Node<'a, 'b, _ => panic!("Unexpected event"), }; - node_a.node.handle_announcement_signatures(&node_b.node.get_our_node_id(), &bs_announcement_sigs); + node_a.node.handle_announcement_signatures(node_b.node.get_our_node_id(), &bs_announcement_sigs); let events_8 = node_a.node.get_and_clear_pending_msg_events(); assert_eq!(events_8.len(), 1); let as_update = match events_8[0] { @@ -1440,19 +1440,19 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: & no_announce_cfg.channel_handshake_config.announce_for_forwarding = false; nodes[a].node.create_channel(nodes[b].node.get_our_node_id(), channel_value, push_msat, 42, None, Some(no_announce_cfg)).unwrap(); let open_channel = get_event_msg!(nodes[a], MessageSendEvent::SendOpenChannel, nodes[b].node.get_our_node_id()); - nodes[b].node.handle_open_channel(&nodes[a].node.get_our_node_id(), &open_channel); + nodes[b].node.handle_open_channel(nodes[a].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, nodes[a].node.get_our_node_id()); - nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), &accept_channel); + nodes[a].node.handle_accept_channel(nodes[b].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42); nodes[a].node.funding_transaction_generated(temporary_channel_id, nodes[b].node.get_our_node_id(), tx.clone()).unwrap(); - nodes[b].node.handle_funding_created(&nodes[a].node.get_our_node_id(), &get_event_msg!(nodes[a], MessageSendEvent::SendFundingCreated, nodes[b].node.get_our_node_id())); + nodes[b].node.handle_funding_created(nodes[a].node.get_our_node_id(), &get_event_msg!(nodes[a], MessageSendEvent::SendFundingCreated, nodes[b].node.get_our_node_id())); check_added_monitors!(nodes[b], 1); let cs_funding_signed = get_event_msg!(nodes[b], MessageSendEvent::SendFundingSigned, nodes[a].node.get_our_node_id()); expect_channel_pending_event(&nodes[b], &nodes[a].node.get_our_node_id()); - nodes[a].node.handle_funding_signed(&nodes[b].node.get_our_node_id(), &cs_funding_signed); + nodes[a].node.handle_funding_signed(nodes[b].node.get_our_node_id(), &cs_funding_signed); expect_channel_pending_event(&nodes[a], &nodes[b].node.get_our_node_id()); check_added_monitors!(nodes[a], 1); @@ -1466,15 +1466,15 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: & confirm_transaction_at(&nodes[b], &tx, conf_height); connect_blocks(&nodes[b], CHAN_CONFIRM_DEPTH - 1); let as_channel_ready = get_event_msg!(nodes[a], MessageSendEvent::SendChannelReady, nodes[b].node.get_our_node_id()); - nodes[a].node.handle_channel_ready(&nodes[b].node.get_our_node_id(), &get_event_msg!(nodes[b], MessageSendEvent::SendChannelReady, nodes[a].node.get_our_node_id())); + nodes[a].node.handle_channel_ready(nodes[b].node.get_our_node_id(), &get_event_msg!(nodes[b], MessageSendEvent::SendChannelReady, nodes[a].node.get_our_node_id())); expect_channel_ready_event(&nodes[a], &nodes[b].node.get_our_node_id()); let as_update = get_event_msg!(nodes[a], MessageSendEvent::SendChannelUpdate, nodes[b].node.get_our_node_id()); - nodes[b].node.handle_channel_ready(&nodes[a].node.get_our_node_id(), &as_channel_ready); + nodes[b].node.handle_channel_ready(nodes[a].node.get_our_node_id(), &as_channel_ready); expect_channel_ready_event(&nodes[b], &nodes[a].node.get_our_node_id()); let bs_update = get_event_msg!(nodes[b], MessageSendEvent::SendChannelUpdate, nodes[a].node.get_our_node_id()); - nodes[a].node.handle_channel_update(&nodes[b].node.get_our_node_id(), &bs_update); - nodes[b].node.handle_channel_update(&nodes[a].node.get_our_node_id(), &as_update); + nodes[a].node.handle_channel_update(nodes[b].node.get_our_node_id(), &bs_update); + nodes[b].node.handle_channel_update(nodes[a].node.get_our_node_id(), &as_update); let mut found_a = false; for chan in nodes[a].node.list_usable_channels() { @@ -1501,14 +1501,16 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: & pub fn update_nodes_with_chan_announce<'a, 'b, 'c, 'd>(nodes: &'a Vec>, a: usize, b: usize, ann: &msgs::ChannelAnnouncement, upd_1: &msgs::ChannelUpdate, upd_2: &msgs::ChannelUpdate) { for node in nodes { - assert!(node.gossip_sync.handle_channel_announcement(ann).unwrap()); - node.gossip_sync.handle_channel_update(upd_1).unwrap(); - node.gossip_sync.handle_channel_update(upd_2).unwrap(); + let node_id_a = nodes[a].node.get_our_node_id(); + let node_id_b = nodes[b].node.get_our_node_id(); + assert!(node.gossip_sync.handle_channel_announcement(None, ann).unwrap()); + node.gossip_sync.handle_channel_update(Some(node_id_a), upd_1).unwrap(); + node.gossip_sync.handle_channel_update(Some(node_id_b), upd_2).unwrap(); // Note that channel_updates are also delivered to ChannelManagers to ensure we have // forwarding info for local channels even if its not accepted in the network graph. - node.node.handle_channel_update(&nodes[a].node.get_our_node_id(), &upd_1); - node.node.handle_channel_update(&nodes[b].node.get_our_node_id(), &upd_2); + node.node.handle_channel_update(node_id_a, &upd_1); + node.node.handle_channel_update(node_id_b, &upd_2); } } @@ -1606,7 +1608,7 @@ fn is_any_peer_connected(node: &Node) -> bool { /// check whether an error message event has occurred. pub fn check_closed_broadcast(node: &Node, num_channels: usize, with_error_msg: bool) -> Vec { let mut dummy_connected = false; - if !is_any_peer_connected(node) { + if !is_any_peer_connected(&node) { connect_dummy_node(&node); dummy_connected = true; } @@ -1765,7 +1767,7 @@ pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: let (tx_a, tx_b); node_a.close_channel(channel_id, &node_b.get_our_node_id()).unwrap(); - node_b.handle_shutdown(&node_a.get_our_node_id(), &get_event_msg!(struct_a, MessageSendEvent::SendShutdown, node_b.get_our_node_id())); + node_b.handle_shutdown(node_a.get_our_node_id(), &get_event_msg!(struct_a, MessageSendEvent::SendShutdown, node_b.get_our_node_id())); let events_1 = node_b.get_and_clear_pending_msg_events(); assert!(events_1.len() >= 1); @@ -1790,17 +1792,17 @@ pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: }) }; - node_a.handle_shutdown(&node_b.get_our_node_id(), &shutdown_b); + node_a.handle_shutdown(node_b.get_our_node_id(), &shutdown_b); let (as_update, bs_update) = if close_inbound_first { assert!(node_a.get_and_clear_pending_msg_events().is_empty()); - node_a.handle_closing_signed(&node_b.get_our_node_id(), &closing_signed_b.unwrap()); + node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap()); - node_b.handle_closing_signed(&node_a.get_our_node_id(), &get_event_msg!(struct_a, MessageSendEvent::SendClosingSigned, node_b.get_our_node_id())); + node_b.handle_closing_signed(node_a.get_our_node_id(), &get_event_msg!(struct_a, MessageSendEvent::SendClosingSigned, node_b.get_our_node_id())); assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1); tx_b = broadcaster_b.txn_broadcasted.lock().unwrap().remove(0); let (bs_update, closing_signed_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id()); - node_a.handle_closing_signed(&node_b.get_our_node_id(), &closing_signed_b.unwrap()); + node_a.handle_closing_signed(node_b.get_our_node_id(), &closing_signed_b.unwrap()); let (as_update, none_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id()); assert!(none_a.is_none()); assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1); @@ -1809,14 +1811,14 @@ pub fn close_channel<'a, 'b, 'c>(outbound_node: &Node<'a, 'b, 'c>, inbound_node: } else { let closing_signed_a = get_event_msg!(struct_a, MessageSendEvent::SendClosingSigned, node_b.get_our_node_id()); - node_b.handle_closing_signed(&node_a.get_our_node_id(), &closing_signed_a); - node_a.handle_closing_signed(&node_b.get_our_node_id(), &get_event_msg!(struct_b, MessageSendEvent::SendClosingSigned, node_a.get_our_node_id())); + node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a); + node_a.handle_closing_signed(node_b.get_our_node_id(), &get_event_msg!(struct_b, MessageSendEvent::SendClosingSigned, node_a.get_our_node_id())); assert_eq!(broadcaster_a.txn_broadcasted.lock().unwrap().len(), 1); tx_a = broadcaster_a.txn_broadcasted.lock().unwrap().remove(0); let (as_update, closing_signed_a) = get_closing_signed_broadcast!(node_a, node_b.get_our_node_id()); - node_b.handle_closing_signed(&node_a.get_our_node_id(), &closing_signed_a.unwrap()); + node_b.handle_closing_signed(node_a.get_our_node_id(), &closing_signed_a.unwrap()); let (bs_update, none_b) = get_closing_signed_broadcast!(node_b, node_a.get_our_node_id()); assert!(none_b.is_none()); assert_eq!(broadcaster_b.txn_broadcasted.lock().unwrap().len(), 1); @@ -1968,7 +1970,7 @@ macro_rules! commitment_signed_dance { { $crate::ln::functional_test_utils::check_added_monitors(&$node_a, 0); assert!($node_a.node.get_and_clear_pending_msg_events().is_empty()); - $node_a.node.handle_commitment_signed(&$node_b.node.get_our_node_id(), &$commitment_signed); + $node_a.node.handle_commitment_signed($node_b.node.get_our_node_id(), &$commitment_signed); check_added_monitors(&$node_a, 1); let (extra_msg_option, bs_revoke_and_ack) = $crate::ln::functional_test_utils::do_main_commitment_signed_dance(&$node_a, &$node_b, $fail_backwards); assert!(extra_msg_option.is_none()); @@ -1995,7 +1997,7 @@ macro_rules! commitment_signed_dance { /// Returns any additional message `node_b` generated in addition to the `revoke_and_ack` response. pub fn commitment_signed_dance_through_cp_raa(node_a: &Node<'_, '_, '_>, node_b: &Node<'_, '_, '_>, fail_backwards: bool, includes_claim: bool) -> Option { let (extra_msg_option, bs_revoke_and_ack) = do_main_commitment_signed_dance(node_a, node_b, fail_backwards); - node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack); + node_a.node.handle_revoke_and_ack(node_b.node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors(node_a, if includes_claim { 0 } else { 1 }); extra_msg_option } @@ -2008,10 +2010,10 @@ pub fn do_main_commitment_signed_dance(node_a: &Node<'_, '_, '_>, node_b: &Node< let (as_revoke_and_ack, as_commitment_signed) = get_revoke_commit_msgs!(node_a, node_b.node.get_our_node_id()); check_added_monitors!(node_b, 0); assert!(node_b.node.get_and_clear_pending_msg_events().is_empty()); - node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack); + node_b.node.handle_revoke_and_ack(node_a.node.get_our_node_id(), &as_revoke_and_ack); assert!(node_b.node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(node_b, 1); - node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &as_commitment_signed); + node_b.node.handle_commitment_signed(node_a.node.get_our_node_id(), &as_commitment_signed); let (bs_revoke_and_ack, extra_msg_option) = { let mut events = node_b.node.get_and_clear_pending_msg_events(); assert!(events.len() <= 2); @@ -2040,7 +2042,7 @@ pub fn do_main_commitment_signed_dance(node_a: &Node<'_, '_, '_>, node_b: &Node< pub fn do_commitment_signed_dance(node_a: &Node<'_, '_, '_>, node_b: &Node<'_, '_, '_>, commitment_signed: &msgs::CommitmentSigned, fail_backwards: bool, skip_last_step: bool) { check_added_monitors!(node_a, 0); assert!(node_a.node.get_and_clear_pending_msg_events().is_empty()); - node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), commitment_signed); + node_a.node.handle_commitment_signed(node_b.node.get_our_node_id(), commitment_signed); check_added_monitors!(node_a, 1); // If this commitment signed dance was due to a claim, don't check for an RAA monitor update. @@ -2545,7 +2547,7 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) { // iterate from the receiving node to the origin node and handle update fail htlc. for (&node, &prev_node) in expected_path.iter().rev().zip(expected_path.iter().rev().skip(1)) { let updates = get_htlc_update_msgs!(node, prev_node.node.get_our_node_id()); - prev_node.node.handle_update_fail_htlc(&node.node.get_our_node_id(), &updates.update_fail_htlcs[0]); + prev_node.node.handle_update_fail_htlc(node.node.get_our_node_id(), &updates.update_fail_htlcs[0]); check_added_monitors!(prev_node, 0); let is_first_hop = origin_node_id == prev_node.node.get_our_node_id(); @@ -2626,7 +2628,7 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option let is_last_hop = idx == expected_path.len() - 1; assert_eq!(node.node.get_our_node_id(), payment_event.node_id); - node.node.handle_update_add_htlc(&prev_node.node.get_our_node_id(), &payment_event.msgs[0]); + node.node.handle_update_add_htlc(prev_node.node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(node, 0); if is_last_hop && is_probe { @@ -2897,7 +2899,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 { macro_rules! last_update_fulfill_dance { ($node: expr, $prev_node: expr) => { { - $node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); + $node.node.handle_update_fulfill_htlc($prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); check_added_monitors!($node, 0); assert!($node.node.get_and_clear_pending_msg_events().is_empty()); commitment_signed_dance!($node, $prev_node, next_msgs.as_ref().unwrap().1, false); @@ -2907,7 +2909,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 { macro_rules! mid_update_fulfill_dance { ($idx: expr, $node: expr, $prev_node: expr, $next_node: expr, $new_msgs: expr) => { { - $node.node.handle_update_fulfill_htlc(&$prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); + $node.node.handle_update_fulfill_htlc($prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); let mut fee = { let (base_fee, prop_fee) = { let per_peer_state = $node.node.per_peer_state.read().unwrap(); @@ -3097,7 +3099,7 @@ pub fn pass_failed_payment_back<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe assert_eq!(expected_next_node, node.node.get_our_node_id()); let update_next_node = !skip_last || idx != expected_route.len() - 1; if next_msgs.is_some() { - node.node.handle_update_fail_htlc(&prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); + node.node.handle_update_fail_htlc(prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); commitment_signed_dance!(node, prev_node, next_msgs.as_ref().unwrap().1, update_next_node); if !update_next_node { expect_pending_htlcs_forwardable_and_htlc_handling_failed!(node, vec![HTLCDestination::NextHopChannel { node_id: Some(prev_node.node.get_our_node_id()), channel_id: next_msgs.as_ref().unwrap().0.channel_id }]); @@ -3130,7 +3132,7 @@ pub fn pass_failed_payment_back<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe if !skip_last { let prev_node = expected_route.first().unwrap(); - origin_node.node.handle_update_fail_htlc(&prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); + origin_node.node.handle_update_fail_htlc(prev_node.node.get_our_node_id(), &next_msgs.as_ref().unwrap().0); check_added_monitors!(origin_node, 0); assert!(origin_node.node.get_and_clear_pending_msg_events().is_empty()); commitment_signed_dance!(origin_node, prev_node, next_msgs.as_ref().unwrap().1, false); @@ -3295,25 +3297,25 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) { +pub fn connect_nodes<'a, 'b: 'a, 'c: 'b>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) { let node_id_a = node_a.node.get_our_node_id(); let node_id_b = node_b.node.get_our_node_id(); let init_a = msgs::Init { - features: node_a.init_features(&node_id_b), + features: node_a.init_features(node_id_b), networks: None, remote_network_address: None, }; let init_b = msgs::Init { - features: node_b.init_features(&node_id_a), + features: node_b.init_features(node_id_a), networks: None, remote_network_address: None, }; - node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap(); - node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap(); - node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap(); - node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap(); + node_a.node.peer_connected(node_id_b, &init_b, true).unwrap(); + node_b.node.peer_connected(node_id_a, &init_a, false).unwrap(); + node_a.onion_messenger.peer_connected(node_id_b, &init_b, true).unwrap(); + node_b.onion_messenger.peer_connected(node_id_a, &init_a, false).unwrap(); } pub fn connect_dummy_node<'a, 'b: 'a, 'c: 'b>(node: &Node<'a, 'b, 'c>) { @@ -3328,14 +3330,14 @@ pub fn connect_dummy_node<'a, 'b: 'a, 'c: 'b>(node: &Node<'a, 'b, 'c>) { remote_network_address: None }; - node.node.peer_connected(&node_id_dummy, &init_dummy, true).unwrap(); - node.onion_messenger.peer_connected(&node_id_dummy, &init_dummy, true).unwrap(); + node.node.peer_connected(node_id_dummy, &init_dummy, true).unwrap(); + node.onion_messenger.peer_connected(node_id_dummy, &init_dummy, true).unwrap(); } pub fn disconnect_dummy_node<'a, 'b: 'a, 'c: 'b>(node: &Node<'a, 'b, 'c>) { let node_id_dummy = PublicKey::from_slice(&[2; 33]).unwrap(); - node.node.peer_disconnected(&node_id_dummy); - node.onion_messenger.peer_disconnected(&node_id_dummy); + node.node.peer_disconnected(node_id_dummy); + node.onion_messenger.peer_disconnected(node_id_dummy); } // Note that the following only works for CLTV values up to 128 @@ -3468,14 +3470,14 @@ pub fn handle_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec { assert_eq!(node_id, nodes[b].node.get_our_node_id()); assert_eq!(msg.as_ref().unwrap().data, expected_error); if needs_err_handle { - nodes[b].node.handle_error(&nodes[a].node.get_our_node_id(), msg.as_ref().unwrap()); + nodes[b].node.handle_error(nodes[a].node.get_our_node_id(), msg.as_ref().unwrap()); } }, _ => panic!("Unexpected event"), @@ -3512,9 +3514,10 @@ pub fn handle_announce_close_broadcast_events<'a, 'b, 'c>(nodes: &Vec(args: ReconnectArgs<'a, 'b, 'c, 'd>) { let mut resp_1 = Vec::new(); for msg in reestablish_1 { - node_b.node.handle_channel_reestablish(&node_a.node.get_our_node_id(), &msg); + node_b.node.handle_channel_reestablish(node_a.node.get_our_node_id(), &msg); resp_1.push(handle_chan_reestablish_msgs!(node_b, node_a)); } if pending_cell_htlc_claims.0 != 0 || pending_cell_htlc_fails.0 != 0 { @@ -3722,7 +3725,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { let mut resp_2 = Vec::new(); for msg in reestablish_2 { - node_a.node.handle_channel_reestablish(&node_b.node.get_our_node_id(), &msg); + node_a.node.handle_channel_reestablish(node_b.node.get_our_node_id(), &msg); resp_2.push(handle_chan_reestablish_msgs!(node_a, node_b)); } if pending_cell_htlc_claims.1 != 0 || pending_cell_htlc_fails.1 != 0 { @@ -3739,7 +3742,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { for chan_msgs in resp_1.drain(..) { if send_channel_ready.0 { - node_a.node.handle_channel_ready(&node_b.node.get_our_node_id(), &chan_msgs.0.unwrap()); + node_a.node.handle_channel_ready(node_b.node.get_our_node_id(), &chan_msgs.0.unwrap()); let announcement_event = node_a.node.get_and_clear_pending_msg_events(); if !announcement_event.is_empty() { assert_eq!(announcement_event.len(), 1); @@ -3752,7 +3755,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { } if pending_raa.0 { assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst); - node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &chan_msgs.1.unwrap()); + node_a.node.handle_revoke_and_ack(node_b.node.get_our_node_id(), &chan_msgs.1.unwrap()); assert!(node_a.node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(node_a, 1); } else { @@ -3768,23 +3771,23 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.0 + pending_cell_htlc_fails.0); assert!(commitment_update.update_fail_malformed_htlcs.is_empty()); for update_add in commitment_update.update_add_htlcs { - node_a.node.handle_update_add_htlc(&node_b.node.get_our_node_id(), &update_add); + node_a.node.handle_update_add_htlc(node_b.node.get_our_node_id(), &update_add); } for update_fulfill in commitment_update.update_fulfill_htlcs { - node_a.node.handle_update_fulfill_htlc(&node_b.node.get_our_node_id(), &update_fulfill); + node_a.node.handle_update_fulfill_htlc(node_b.node.get_our_node_id(), &update_fulfill); } for update_fail in commitment_update.update_fail_htlcs { - node_a.node.handle_update_fail_htlc(&node_b.node.get_our_node_id(), &update_fail); + node_a.node.handle_update_fail_htlc(node_b.node.get_our_node_id(), &update_fail); } if !pending_responding_commitment_signed.0 { commitment_signed_dance!(node_a, node_b, commitment_update.commitment_signed, false); } else { - node_a.node.handle_commitment_signed(&node_b.node.get_our_node_id(), &commitment_update.commitment_signed); + node_a.node.handle_commitment_signed(node_b.node.get_our_node_id(), &commitment_update.commitment_signed); check_added_monitors!(node_a, 1); let as_revoke_and_ack = get_event_msg!(node_a, MessageSendEvent::SendRevokeAndACK, node_b.node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes - node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &as_revoke_and_ack); + node_b.node.handle_revoke_and_ack(node_a.node.get_our_node_id(), &as_revoke_and_ack); assert!(node_b.node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(node_b, if pending_responding_commitment_signed_dup_monitor.0 { 0 } else { 1 }); } @@ -3795,7 +3798,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { for chan_msgs in resp_2.drain(..) { if send_channel_ready.1 { - node_b.node.handle_channel_ready(&node_a.node.get_our_node_id(), &chan_msgs.0.unwrap()); + node_b.node.handle_channel_ready(node_a.node.get_our_node_id(), &chan_msgs.0.unwrap()); let announcement_event = node_b.node.get_and_clear_pending_msg_events(); if !announcement_event.is_empty() { assert_eq!(announcement_event.len(), 1); @@ -3810,7 +3813,7 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { } if pending_raa.1 { assert!(chan_msgs.3 == RAACommitmentOrder::RevokeAndACKFirst); - node_b.node.handle_revoke_and_ack(&node_a.node.get_our_node_id(), &chan_msgs.1.unwrap()); + node_b.node.handle_revoke_and_ack(node_a.node.get_our_node_id(), &chan_msgs.1.unwrap()); assert!(node_b.node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(node_b, 1); } else { @@ -3826,23 +3829,23 @@ pub fn reconnect_nodes<'a, 'b, 'c, 'd>(args: ReconnectArgs<'a, 'b, 'c, 'd>) { assert_eq!(commitment_update.update_fail_htlcs.len(), pending_htlc_fails.1 + pending_cell_htlc_fails.1); assert!(commitment_update.update_fail_malformed_htlcs.is_empty()); for update_add in commitment_update.update_add_htlcs { - node_b.node.handle_update_add_htlc(&node_a.node.get_our_node_id(), &update_add); + node_b.node.handle_update_add_htlc(node_a.node.get_our_node_id(), &update_add); } for update_fulfill in commitment_update.update_fulfill_htlcs { - node_b.node.handle_update_fulfill_htlc(&node_a.node.get_our_node_id(), &update_fulfill); + node_b.node.handle_update_fulfill_htlc(node_a.node.get_our_node_id(), &update_fulfill); } for update_fail in commitment_update.update_fail_htlcs { - node_b.node.handle_update_fail_htlc(&node_a.node.get_our_node_id(), &update_fail); + node_b.node.handle_update_fail_htlc(node_a.node.get_our_node_id(), &update_fail); } if !pending_responding_commitment_signed.1 { commitment_signed_dance!(node_b, node_a, commitment_update.commitment_signed, false); } else { - node_b.node.handle_commitment_signed(&node_a.node.get_our_node_id(), &commitment_update.commitment_signed); + node_b.node.handle_commitment_signed(node_a.node.get_our_node_id(), &commitment_update.commitment_signed); check_added_monitors!(node_b, 1); let bs_revoke_and_ack = get_event_msg!(node_b, MessageSendEvent::SendRevokeAndACK, node_a.node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes - node_a.node.handle_revoke_and_ack(&node_b.node.get_our_node_id(), &bs_revoke_and_ack); + node_a.node.handle_revoke_and_ack(node_b.node.get_our_node_id(), &bs_revoke_and_ack); assert!(node_a.node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(node_a, if pending_responding_commitment_signed_dup_monitor.1 { 0 } else { 1 }); } @@ -3871,9 +3874,9 @@ pub fn create_batch_channel_funding<'a, 'b, 'c>( *override_config, ).unwrap(); let open_channel_msg = get_event_msg!(funding_node, MessageSendEvent::SendOpenChannel, other_node.node.get_our_node_id()); - other_node.node.handle_open_channel(&funding_node.node.get_our_node_id(), &open_channel_msg); + other_node.node.handle_open_channel(funding_node.node.get_our_node_id(), &open_channel_msg); let accept_channel_msg = get_event_msg!(other_node, MessageSendEvent::SendAcceptChannel, funding_node.node.get_our_node_id()); - funding_node.node.handle_accept_channel(&other_node.node.get_our_node_id(), &accept_channel_msg); + funding_node.node.handle_accept_channel(other_node.node.get_our_node_id(), &accept_channel_msg); // Create the corresponding funding output. let events = funding_node.node.get_and_clear_pending_events(); diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 22b7df1ed38..efd2fc9e9d6 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -74,21 +74,21 @@ fn test_channel_resumption_fail_post_funding() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 0, 42, None, None).unwrap(); let open_chan = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan); let accept_chan = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_chan); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_chan); let (temp_chan_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42); let new_chan_id = ChannelId::v1_from_funding_outpoint(funding_output); nodes[0].node.funding_transaction_generated(temp_chan_id, nodes[1].node.get_our_node_id(), tx).unwrap(); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); check_closed_events(&nodes[0], &[ExpectedCloseEvent::from_id_reason(new_chan_id, true, ClosureReason::DisconnectedPeer)]); // After ddf75afd16 we'd panic on reconnection if we exchanged funding info, so test that // explicitly here. - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); assert_eq!(nodes[0].node.get_and_clear_pending_msg_events(), Vec::new()); @@ -120,7 +120,7 @@ fn test_insane_channel_opens() { // Test helper that asserts we get the correct error string given a mutator // that supposedly makes the channel open message insane let insane_open_helper = |expected_error_str: &str, message_mutator: fn(msgs::OpenChannel) -> msgs::OpenChannel| { - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &message_mutator(open_channel_message.clone())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &message_mutator(open_channel_message.clone())); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); let expected_regex = regex::Regex::new(expected_error_str).unwrap(); @@ -198,7 +198,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) { open_channel_message.channel_reserve_satoshis = 0; open_channel_message.common_fields.max_htlc_value_in_flight_msat = 100_000_000; } - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_message); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_message); // Extract the channel accept message from node1 to node0 let mut accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); @@ -206,7 +206,7 @@ fn do_test_counterparty_no_reserve(send_from_initiator: bool) { accept_channel_message.channel_reserve_satoshis = 0; accept_channel_message.common_fields.max_htlc_value_in_flight_msat = 100_000_000; } - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel_message); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel_message); { let sender_node = if send_from_initiator { &nodes[1] } else { &nodes[0] }; let counterparty_node = if send_from_initiator { &nodes[0] } else { &nodes[1] }; @@ -292,7 +292,7 @@ fn test_async_inbound_update_fee() { _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); // ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]... let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000); @@ -309,19 +309,19 @@ fn test_async_inbound_update_fee() { assert_eq!(payment_event.msgs.len(), 1); // ...now when the messages get delivered everyone should be happy - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); // (2) + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); // (2) let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // nodes[0] is awaiting nodes[1] revoke_and_ack so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); // deliver(1), generate (3): - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let bs_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // nodes[1] is awaiting nodes[0] revoke_and_ack so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); // deliver (2) + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); // deliver (2) let bs_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(bs_update.update_add_htlcs.is_empty()); // (4) assert!(bs_update.update_fulfill_htlcs.is_empty()); // (4) @@ -330,7 +330,7 @@ fn test_async_inbound_update_fee() { assert!(bs_update.update_fee.is_none()); // (4) check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); // deliver (3) + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); // deliver (3) let as_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert!(as_update.update_add_htlcs.is_empty()); // (5) assert!(as_update.update_fulfill_htlcs.is_empty()); // (5) @@ -339,16 +339,16 @@ fn test_async_inbound_update_fee() { assert!(as_update.update_fee.is_none()); // (5) check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_update.commitment_signed); // deliver (4) + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_update.commitment_signed); // deliver (4) let as_second_revoke = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // only (6) so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_update.commitment_signed); // deliver (5) + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_update.commitment_signed); // deliver (5) let bs_second_revoke = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_revoke); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_revoke); check_added_monitors!(nodes[0], 1); let events_2 = nodes[0].node.get_and_clear_pending_events(); @@ -358,7 +358,7 @@ fn test_async_inbound_update_fee() { _ => panic!("Unexpected event"), } - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_revoke); // deliver (6) + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_revoke); // deliver (6) check_added_monitors!(nodes[1], 1); } @@ -392,7 +392,7 @@ fn test_update_fee_unordered_raa() { _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); // ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]... let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 40000); @@ -409,13 +409,13 @@ fn test_update_fee_unordered_raa() { assert_eq!(payment_event.msgs.len(), 1); // ...now when the messages get delivered everyone should be happy - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); // (2) + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); // (2) let as_revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // nodes[0] is awaiting nodes[1] revoke_and_ack so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_msg); // deliver (2) + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_msg); // deliver (2) check_added_monitors!(nodes[1], 1); // We can't continue, sadly, because our (1) now has a bogus signature @@ -468,8 +468,8 @@ fn test_multi_flight_update_fee() { }; // Deliver first update_fee/commitment_signed pair, generating (1) and (2): - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg_1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed_1); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg_1); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed_1); let (bs_revoke_msg, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); @@ -489,14 +489,14 @@ fn test_multi_flight_update_fee() { feerate_per_kw: (initial_feerate + 30) as u32, }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &update_msg_2); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &update_msg_2); update_msg_2.feerate_per_kw = (initial_feerate + 40) as u32; // Deliver (3) - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &update_msg_2); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &update_msg_2); // Deliver (1), generating (3) and (4) - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_msg); let as_second_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); assert!(as_second_update.update_add_htlcs.is_empty()); @@ -508,30 +508,30 @@ fn test_multi_flight_update_fee() { assert_eq!(as_second_update.update_fee.as_ref().unwrap().feerate_per_kw, update_msg_2.feerate_per_kw); // Deliver (2) commitment_signed - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_commitment_signed); let as_revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); // No commitment_signed so get_event_msg's assert(len == 1) passes - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_msg); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); // Delever (4) - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_update.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_second_update.commitment_signed); let (bs_second_revoke, bs_second_commitment) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_revoke); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_revoke); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_commitment); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_commitment); let as_second_revoke = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_revoke); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_revoke); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); } @@ -558,11 +558,11 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) { let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); if steps & 0x0f == 1 { return; } - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); if steps & 0x0f == 2 { return; } - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); @@ -572,7 +572,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) { let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); if steps & 0x0f == 4 { return; } - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); { let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -584,7 +584,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) { let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); if steps & 0x0f == 5 { return; } - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); { let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -651,22 +651,22 @@ fn test_update_fee_vanilla() { }, _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let (revoke_msg, commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke_msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed); let revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &revoke_msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &revoke_msg); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); } @@ -701,7 +701,7 @@ fn test_update_fee_that_funder_cannot_afford() { check_added_monitors!(nodes[0], 1); let update_msg = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &update_msg.update_fee.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &update_msg.update_fee.unwrap()); commitment_signed_dance!(nodes[1], nodes[0], update_msg.commitment_signed, false); @@ -793,12 +793,12 @@ fn test_update_fee_that_funder_cannot_afford() { feerate_per_kw: non_buffer_feerate + 4, }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &update_fee); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &update_fee); //While producing the commitment_signed response after handling a received update_fee request the //check to see if the funder, who sent the update_fee request, can afford the new fee (funder_balance >= fee+channel_reserve) //Should produce and error. - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commit_signed_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commit_signed_msg); nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Funding remote cannot afford proposed new fee", 3); check_added_monitors!(nodes[1], 1); check_closed_broadcast!(nodes[1], true); @@ -832,8 +832,8 @@ fn test_update_fee_with_fundee_update_add_htlc() { }, _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let (revoke_msg, commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); @@ -851,15 +851,15 @@ fn test_update_fee_with_fundee_update_add_htlc() { assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); // node[1] has nothing to do - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke_msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed); let revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &revoke_msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &revoke_msg); check_added_monitors!(nodes[1], 1); // AwaitingRemoteRevoke ends here @@ -870,21 +870,21 @@ fn test_update_fee_with_fundee_update_add_htlc() { assert_eq!(commitment_update.update_fail_malformed_htlcs.len(), 0); assert_eq!(commitment_update.update_fee.is_none(), true); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &commitment_update.update_add_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_update.commitment_signed); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &commitment_update.update_add_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_update.commitment_signed); check_added_monitors!(nodes[0], 1); let (revoke, commitment_signed) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &revoke); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &revoke); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commitment_signed); check_added_monitors!(nodes[1], 1); let revoke = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke); check_added_monitors!(nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); @@ -947,15 +947,15 @@ fn test_update_fee() { }, _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); // Generate (2) and (3): - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let (revoke_msg, commitment_signed_0) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); // Deliver (2): - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke_msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); @@ -975,26 +975,26 @@ fn test_update_fee() { _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); check_added_monitors!(nodes[1], 1); // ... creating (5) let revoke_msg = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes // Handle (3), creating (6): - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed_0); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed_0); check_added_monitors!(nodes[0], 1); let revoke_msg_0 = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes // Deliver (5): - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke_msg); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); // Deliver (6), creating (7): - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &revoke_msg_0); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &revoke_msg_0); let commitment_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(commitment_update.update_add_htlcs.is_empty()); assert!(commitment_update.update_fulfill_htlcs.is_empty()); @@ -1004,12 +1004,12 @@ fn test_update_fee() { check_added_monitors!(nodes[1], 1); // Deliver (7) - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_update.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_update.commitment_signed); check_added_monitors!(nodes[0], 1); let revoke_msg = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &revoke_msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &revoke_msg); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -1200,7 +1200,7 @@ fn holding_cell_htlc_counting() { let payment_event = SendEvent::from_event(events.pop().unwrap()); assert_eq!(payment_event.node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // We have to forward pending HTLCs twice - once tries to forward the payment forward (and // fails), the second will process the resulting failure and fail the HTLC backward. @@ -1209,41 +1209,41 @@ fn holding_cell_htlc_counting() { check_added_monitors!(nodes[1], 1); let bs_fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_fail_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_fail_updates.commitment_signed, false, true); expect_payment_failed_with_update!(nodes[0], payment_hash_2, false, chan_2.0.contents.short_channel_id, false); // Now forward all the pending HTLCs and claim them back - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &initial_payment_event.msgs[0]); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &initial_payment_event.commitment_msg); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &initial_payment_event.msgs[0]); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &initial_payment_event.commitment_msg); check_added_monitors!(nodes[2], 1); let (bs_revoke_and_ack, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors!(nodes[1], 1); let as_updates = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &bs_commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &bs_commitment_signed); check_added_monitors!(nodes[1], 1); let as_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); for ref update in as_updates.update_add_htlcs.iter() { - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), update); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), update); } - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &as_updates.commitment_signed); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &as_updates.commitment_signed); check_added_monitors!(nodes[2], 1); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[2], 1); let (bs_revoke_and_ack, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &bs_commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &bs_commitment_signed); check_added_monitors!(nodes[1], 1); let as_final_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_final_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_final_raa); check_added_monitors!(nodes[2], 1); expect_pending_htlcs_forwardable!(nodes[2]); @@ -1450,7 +1450,7 @@ fn test_fee_spike_violation_fails_htlc() { blinding_point: None, }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &msg); // Now manually create the commitment_signed message corresponding to the update_add // nodes[0] just sent. In the code for construction of this message, "local" refers @@ -1539,7 +1539,7 @@ fn test_fee_spike_violation_fails_htlc() { }; // Send the commitment_signed message to the nodes[1]. - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commit_signed_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commit_signed_msg); let _ = nodes[1].node.get_and_clear_pending_msg_events(); // Send the RAA to nodes[1]. @@ -1550,7 +1550,7 @@ fn test_fee_spike_violation_fails_htlc() { #[cfg(taproot)] next_local_nonce: None, }; - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa_msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa_msg); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -1649,7 +1649,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() { blinding_point: None, }; - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &msg); // Check that the payment failed and the channel is closed in response to the malicious UpdateAdd. nodes[0].logger.assert_log_contains("lightning::ln::channelmanager", "Cannot accept HTLC that would put our balance under counterparty-announced channel reserve value", 3); assert_eq!(nodes[0].node.list_channels().len(), 0); @@ -1727,7 +1727,7 @@ fn test_chan_init_feerate_unaffordability() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, push_amt, 42, None, None).unwrap(); let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); open_channel_msg.push_msat += 1; - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); @@ -1800,7 +1800,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event_1.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event_1.msgs[0]); // Attempt to trigger a channel reserve violation --> payment failure. let commit_tx_fee_2_htlcs = commit_tx_fee_msat(feerate, 2, &channel_type_features); @@ -1829,7 +1829,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() { blinding_point: None, }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &msg); // Check that the payment failed and the channel is closed in response to the malicious UpdateAdd. nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Remote HTLC add would put them under remote reserve value", 3); assert_eq!(nodes[1].node.list_channels().len(), 1); @@ -1973,7 +1973,7 @@ fn test_channel_reserve_holding_cell_htlcs() { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event_1.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event_1.msgs[0]); // channel reserve test with htlc pending output > 0 let recv_value_2 = stat01.value_to_self_msat - amt_msat_1 - stat01.channel_reserve_msat - total_fee_msat - commit_tx_fee_2_htlcs; @@ -2026,28 +2026,28 @@ fn test_channel_reserve_holding_cell_htlcs() { assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); // flush the pending htlc - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event_1.commitment_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event_1.commitment_msg); let (as_revoke_and_ack, as_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); // the pending htlc should be promoted to committed - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_revoke_and_ack); check_added_monitors!(nodes[0], 1); let commitment_update_2 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &as_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &as_commitment_signed); let bs_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &bs_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable!(nodes[1]); let ref payment_event_11 = expect_forward!(nodes[1]); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_11.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_11.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], payment_event_11.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -2055,15 +2055,15 @@ fn test_channel_reserve_holding_cell_htlcs() { // flush the htlcs in the holding cell assert_eq!(commitment_update_2.update_add_htlcs.len(), 2); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &commitment_update_2.update_add_htlcs[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &commitment_update_2.update_add_htlcs[1]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &commitment_update_2.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &commitment_update_2.update_add_htlcs[1]); commitment_signed_dance!(nodes[1], nodes[0], &commitment_update_2.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[1]); let ref payment_event_3 = expect_forward!(nodes[1]); assert_eq!(payment_event_3.msgs.len(), 2); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_3.msgs[0]); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event_3.msgs[1]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_3.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event_3.msgs[1]); commitment_signed_dance!(nodes[2], nodes[1], &payment_event_3.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -2182,27 +2182,27 @@ fn channel_reserve_in_flight_removes() { check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_removes.update_fulfill_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_removes.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_removes.update_fulfill_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_removes.commitment_signed); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); expect_payment_sent(&nodes[0], payment_preimage_1, None, false, false); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_1.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_1.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_1.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &send_1.commitment_msg); check_added_monitors!(nodes[1], 1); // B is already AwaitingRAA, so cant generate a CS here let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); let bs_cs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); let as_cs = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); @@ -2211,13 +2211,13 @@ fn channel_reserve_in_flight_removes() { // However, the RAA A generates here *does* fully resolve the HTLC from B's point of view (as A // can no longer broadcast a commitment transaction with it and B has the preimage so can go // on-chain as necessary). - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_cs.update_fulfill_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_cs.update_fulfill_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs.commitment_signed); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); expect_payment_sent(&nodes[0], payment_preimage_2, None, false, false); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -2226,7 +2226,7 @@ fn channel_reserve_in_flight_removes() { // Note that as this RAA was generated before the delivery of the update_fulfill it shouldn't // resolve the second HTLC from A's point of view. - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); let as_cs = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -2243,30 +2243,30 @@ fn channel_reserve_in_flight_removes() { SendEvent::from_event(events.remove(0)) }; - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_2.msgs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_2.commitment_msg); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_2.msgs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &send_2.commitment_msg); check_added_monitors!(nodes[0], 1); let as_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // Now just resolve all the outstanding messages/HTLCs for completeness... - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); let as_cs = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs.commitment_signed); check_added_monitors!(nodes[1], 1); let bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); expect_pending_htlcs_forwardable!(nodes[0]); @@ -2461,14 +2461,16 @@ fn channel_monitor_network_test() { check_preimage_claim(&nodes[4], &node_txn); (close_chan_update_1, close_chan_update_2) }; - nodes[3].gossip_sync.handle_channel_update(&close_chan_update_2).unwrap(); - nodes[4].gossip_sync.handle_channel_update(&close_chan_update_1).unwrap(); + let node_id_4 = nodes[4].node.get_our_node_id(); + let node_id_3 = nodes[3].node.get_our_node_id(); + nodes[3].gossip_sync.handle_channel_update(Some(node_id_4), &close_chan_update_2).unwrap(); + nodes[4].gossip_sync.handle_channel_update(Some(node_id_3), &close_chan_update_1).unwrap(); assert_eq!(nodes[3].node.list_channels().len(), 0); assert_eq!(nodes[4].node.list_channels().len(), 0); assert_eq!(nodes[3].chain_monitor.chain_monitor.watch_channel(OutPoint { txid: chan_3.3.compute_txid(), index: 0 }, chan_3_mon), Ok(ChannelMonitorUpdateStatus::Completed)); - check_closed_event!(nodes[3], 1, ClosureReason::HTLCsTimedOut, [nodes[4].node.get_our_node_id()], 100000); + check_closed_event!(nodes[3], 1, ClosureReason::HTLCsTimedOut, [node_id_4], 100000); } #[test] @@ -3233,7 +3235,7 @@ fn test_simple_commitment_revoked_fail_backward() { assert!(update_fail_malformed_htlcs.is_empty()); assert_eq!(nodes[0].node.get_our_node_id(), *node_id); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false, true); expect_payment_failed_with_update!(nodes[0], payment_hash, false, chan_2.0.contents.short_channel_id, true); }, @@ -3293,7 +3295,7 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use assert!(updates.update_fail_malformed_htlcs.is_empty()); assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); let bs_raa = commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false, true, false, true); // Drop the last RAA from 3 -> 2 @@ -3306,12 +3308,12 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use assert!(updates.update_fail_malformed_htlcs.is_empty()); assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[1], 1); // Note that nodes[1] is in AwaitingRAA, so won't send a CS let as_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[2], 1); nodes[2].node.fail_htlc_backwards(&third_payment_hash); @@ -3323,14 +3325,14 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use assert!(updates.update_fail_malformed_htlcs.is_empty()); assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fee.is_none()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); // At this point first_payment_hash has dropped out of the latest two commitment // transactions that nodes[1] is tracking... - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[1], 1); // Note that nodes[1] is (still) in AwaitingRAA, so won't send a CS let as_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_raa); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_raa); check_added_monitors!(nodes[2], 1); // Add a fourth HTLC, this one will get sequestered away in nodes[1]'s holding cell waiting @@ -3343,7 +3345,7 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use check_added_monitors!(nodes[1], 0); if deliver_bs_raa { - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_raa); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &bs_raa); // One monitor for the new revocation preimage, no second on as we won't generate a new // commitment transaction for nodes[0] until process_pending_htlc_forwards(). check_added_monitors!(nodes[1], 1); @@ -3421,9 +3423,9 @@ fn do_test_commitment_revoked_fail_backward_exhaustive(deliver_bs_raa: bool, use assert!(update_fail_malformed_htlcs.is_empty()); assert_eq!(nodes[0].node.get_our_node_id(), *node_id); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[1]); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[2]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[1]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[2]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false, true); @@ -3559,7 +3561,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() { skimmed_fee_msat: None, blinding_point: None, }; - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_htlc); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add_htlc); } let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 3); @@ -3647,7 +3649,7 @@ fn test_force_close_fail_back() { SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -3658,8 +3660,8 @@ fn test_force_close_fail_back() { assert_eq!(payment_event.msgs.len(), 1); check_added_monitors!(nodes[1], 1); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[2], 1); let (_, _) = get_revoke_commit_msgs!(nodes[2], nodes[1].node.get_our_node_id()); @@ -3723,11 +3725,11 @@ fn test_dup_events_on_peer_disconnect() { expect_payment_claimed!(nodes[1], payment_hash, 1_000_000); check_added_monitors!(nodes[1], 1); let claim_msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &claim_msgs.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &claim_msgs.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); reconnect_args.pending_htlc_claims.0 = 1; @@ -3748,9 +3750,9 @@ fn test_peer_disconnected_before_funding_broadcasted() { // broadcasted, even though it's created by `nodes[0]`. let expected_temporary_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42); assert_eq!(temporary_channel_id, expected_temporary_channel_id); @@ -3768,8 +3770,8 @@ fn test_peer_disconnected_before_funding_broadcasted() { } // The peers disconnect before the funding is broadcasted. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // The time for peers to reconnect expires. for _ in 0..UNFUNDED_CHANNEL_AGE_LIMIT_TICKS { @@ -3795,8 +3797,8 @@ fn test_simple_peer_disconnect() { create_announced_chan_between_nodes(&nodes, 0, 1); create_announced_chan_between_nodes(&nodes, 1, 2); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); reconnect_args.send_channel_ready = (true, true); reconnect_nodes(reconnect_args); @@ -3806,8 +3808,8 @@ fn test_simple_peer_disconnect() { fail_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), payment_hash_2); claim_payment(&nodes[0], &vec!(&nodes[1], &nodes[2]), payment_preimage_1); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); let (payment_preimage_3, payment_hash_3, ..) = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000); @@ -3815,8 +3817,8 @@ fn test_simple_peer_disconnect() { let payment_hash_5 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).1; let payment_hash_6 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).1; - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); claim_payment_along_route( ClaimAlongRouteArgs::new(&nodes[0], &[&[&nodes[1], &nodes[2]]], payment_preimage_3) @@ -3897,25 +3899,25 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken if messages_delivered < 2 { // Drop the payment_event messages, and let them get re-generated in reconnect_nodes! } else { - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); if messages_delivered >= 3 { - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_revoke_and_ack, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); if messages_delivered >= 4 { - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); if messages_delivered >= 5 { - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_commitment_signed); let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); if messages_delivered >= 6 { - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); } @@ -3924,8 +3926,8 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken } } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); if messages_delivered < 3 { if simulate_broken_lnd { // lnd has a long-standing bug where they send a channel_ready prior to a @@ -3936,7 +3938,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken // in `reconnect_nodes` but we currently don't fail based on that. // // See-also - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready.as_ref().unwrap().0); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready.as_ref().unwrap().0); } // Even if the channel_ready messages get exchanged, as long as nothing further was // received on either side, both sides will need to resend them. @@ -3984,8 +3986,8 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken }; } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); nodes[1].node.process_pending_htlc_forwards(); @@ -4029,7 +4031,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken }; if messages_delivered >= 1 { - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_htlc); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_htlc); let events_4 = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events_4.len(), 1); @@ -4042,23 +4044,23 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken } if messages_delivered >= 2 { - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed); check_added_monitors!(nodes[0], 1); let (as_revoke_and_ack, as_commitment_signed) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); if messages_delivered >= 3 { - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); if messages_delivered >= 4 { - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_commitment_signed); let bs_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); if messages_delivered >= 5 { - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); } @@ -4067,8 +4069,8 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken } } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); if messages_delivered < 2 { let mut reconnect_args = ReconnectArgs::new(&nodes[0], &nodes[1]); reconnect_args.pending_htlc_claims.0 = 1; @@ -4103,8 +4105,8 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken expect_payment_path_successful!(nodes[0]); } if messages_delivered <= 5 { - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); } reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); @@ -4157,7 +4159,7 @@ fn test_channel_ready_without_best_block_updated() { // Ensure nodes[0] generates a channel_ready after the transactions_confirmed let as_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); } #[test] @@ -4189,7 +4191,7 @@ fn test_channel_monitor_skipping_block_when_channel_manager_is_leading() { // Ensure nodes[0] generates a channel_ready after the transactions_confirmed let as_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); } #[test] @@ -4224,7 +4226,7 @@ fn test_channel_monitor_skipping_block_when_channel_manager_is_lagging() { // Ensure nodes[0] generates a channel_ready after the transactions_confirmed let as_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); } #[test] @@ -4267,7 +4269,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { assert!(update_fail_malformed_htlcs.is_empty()); assert!(update_fee.is_none()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); let events_3 = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events_3.len(), 1); match events_3[0] { @@ -4278,7 +4280,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { _ => panic!("Unexpected event"), } - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), commitment_signed); let _ = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); @@ -4286,23 +4288,23 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { _ => panic!("Unexpected event"), } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 1); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); let as_resp = handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); let bs_resp = handle_chan_reestablish_msgs!(nodes[1], nodes[0]); assert!(as_resp.0.is_none()); @@ -4318,13 +4320,13 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { assert!(as_resp.2.as_ref().unwrap().update_fail_htlcs.is_empty()); assert!(as_resp.2.as_ref().unwrap().update_fail_malformed_htlcs.is_empty()); assert!(as_resp.2.as_ref().unwrap().update_fee.is_none()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().update_add_htlcs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().commitment_signed); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().update_add_htlcs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_resp.2.as_ref().unwrap().commitment_signed); let bs_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), as_resp.1.as_ref().unwrap()); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), as_resp.1.as_ref().unwrap()); let bs_second_commitment_signed = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(bs_second_commitment_signed.update_add_htlcs.is_empty()); assert!(bs_second_commitment_signed.update_fulfill_htlcs.is_empty()); @@ -4333,7 +4335,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { assert!(bs_second_commitment_signed.update_fee.is_none()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); let as_commitment_signed = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); assert!(as_commitment_signed.update_add_htlcs.is_empty()); assert!(as_commitment_signed.update_fulfill_htlcs.is_empty()); @@ -4342,17 +4344,17 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { assert!(as_commitment_signed.update_fee.is_none()); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_commitment_signed.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_commitment_signed.commitment_signed); let as_revoke_and_ack = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_commitment_signed.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_commitment_signed.commitment_signed); let bs_second_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); // No commitment_signed so get_event_msg's assert(len == 1) passes check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_revoke_and_ack); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[1], 1); @@ -4374,7 +4376,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { _ => panic!("Unexpected event"), } - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_revoke_and_ack); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); check_added_monitors!(nodes[0], 1); @@ -4433,7 +4435,7 @@ fn do_test_htlc_timeout(send_partial_mpp: bool) { assert!(htlc_timeout_updates.update_fail_malformed_htlcs.is_empty()); assert!(htlc_timeout_updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], htlc_timeout_updates.commitment_signed, false); // 100_000 msat as u64, followed by the height at which we failed back above let mut expected_failure_data = (100_000 as u64).to_be_bytes().to_vec(); @@ -4476,7 +4478,7 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) { if forwarded_htlc { check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); } @@ -4494,7 +4496,7 @@ fn do_test_holding_cell_htlc_add_timeouts(forwarded_htlc: bool) { assert_eq!(fail_commit.len(), 1); match fail_commit[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fail_htlcs, ref commitment_signed, .. }, .. } => { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, true, true); }, _ => unreachable!(), @@ -5145,7 +5147,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() { assert!(htlc_updates.update_fail_malformed_htlcs.is_empty()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); { commitment_signed_dance!(nodes[0], nodes[1], &htlc_updates.commitment_signed, false, true); @@ -5163,7 +5165,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() { assert!(updates.update_fail_malformed_htlcs.is_empty()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], &updates.commitment_signed, false); expect_payment_sent(&nodes[0], our_payment_preimage, None, true, true); } @@ -5312,10 +5314,10 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno check_added_monitors!(nodes[4], 1); let four_removes = get_htlc_update_msgs!(nodes[4], nodes[3].node.get_our_node_id()); - nodes[3].node.handle_update_fail_htlc(&nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[0]); - nodes[3].node.handle_update_fail_htlc(&nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[1]); - nodes[3].node.handle_update_fail_htlc(&nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[2]); - nodes[3].node.handle_update_fail_htlc(&nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[3]); + nodes[3].node.handle_update_fail_htlc(nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[0]); + nodes[3].node.handle_update_fail_htlc(nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[1]); + nodes[3].node.handle_update_fail_htlc(nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[2]); + nodes[3].node.handle_update_fail_htlc(nodes[4].node.get_our_node_id(), &four_removes.update_fail_htlcs[3]); commitment_signed_dance!(nodes[3], nodes[4], four_removes.commitment_signed, false); // Fail 3rd below-dust and 7th above-dust HTLCs @@ -5331,8 +5333,8 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno check_added_monitors!(nodes[5], 1); let two_removes = get_htlc_update_msgs!(nodes[5], nodes[3].node.get_our_node_id()); - nodes[3].node.handle_update_fail_htlc(&nodes[5].node.get_our_node_id(), &two_removes.update_fail_htlcs[0]); - nodes[3].node.handle_update_fail_htlc(&nodes[5].node.get_our_node_id(), &two_removes.update_fail_htlcs[1]); + nodes[3].node.handle_update_fail_htlc(nodes[5].node.get_our_node_id(), &two_removes.update_fail_htlcs[0]); + nodes[3].node.handle_update_fail_htlc(nodes[5].node.get_our_node_id(), &two_removes.update_fail_htlcs[1]); commitment_signed_dance!(nodes[3], nodes[5], two_removes.commitment_signed, false); let ds_prev_commitment_tx = get_local_commitment_txn!(nodes[3], chan_2_3.2); @@ -5349,12 +5351,12 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], failed_destinations_3); check_added_monitors!(nodes[3], 1); let six_removes = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[0]); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[1]); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[2]); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[3]); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[4]); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[5]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[1]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[2]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[3]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[4]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &six_removes.update_fail_htlcs[5]); if deliver_last_raa { commitment_signed_dance!(nodes[2], nodes[3], six_removes.commitment_signed, false); } else { @@ -5436,13 +5438,13 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno assert_eq!(updates.update_fail_htlcs.len(), if announce_latest { 4 } else { 3 }); &nodes[1] }; - target.node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); - target.node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[1]); - target.node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[2]); + target.node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + target.node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[1]); + target.node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[2]); if announce_latest { - target.node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[3]); + target.node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[3]); if *node_id == nodes[0].node.get_our_node_id() { - target.node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[4]); + target.node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[4]); } } commitment_signed_dance!(target, nodes[2], updates.commitment_signed, false, true); @@ -5708,13 +5710,13 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) { expect_payment_claimed!(nodes[1], payment_hash, if use_dust { 50000 } else { 3_000_000 }); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); check_added_monitors!(nodes[0], 1); let as_updates = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_updates.0); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_updates.0); check_added_monitors!(nodes[1], 1); let starting_block = nodes[1].best_block_info(); @@ -5778,18 +5780,18 @@ fn do_htlc_claim_previous_remote_commitment_only(use_dust: bool, check_revoke_no check_added_monitors!(nodes[1], 1); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_updates.commitment_signed); check_added_monitors!(nodes[0], 1); let as_updates = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_updates.0); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_updates.0); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.1); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_updates.1); check_added_monitors!(nodes[1], 1); let bs_revoke_and_ack = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); if check_revoke_no_close { - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_revoke_and_ack); check_added_monitors!(nodes[0], 1); } @@ -5854,7 +5856,7 @@ fn bolt2_open_channel_sending_node_checks_part1() { //This test needs to be on i let push_msat=10001; nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None, None).unwrap(); let node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel); get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); // Create a second channel with the same random values. This used to panic due to a colliding @@ -5921,7 +5923,7 @@ fn bolt2_open_channel_sane_dust_limit() { node0_to_1_send_open_channel.common_fields.dust_limit_satoshis = 547; node0_to_1_send_open_channel.channel_reserve_satoshis = 100001; - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &node0_to_1_send_open_channel); let events = nodes[1].node.get_and_clear_pending_msg_events(); let err_msg = match events[0] { MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg }, node_id: _ } => { @@ -5962,7 +5964,7 @@ fn test_fail_holding_cell_htlc_upon_free() { _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); let mut chan_stat = get_channel_value_stat!(nodes[0], nodes[1], chan.2); let channel_reserve = chan_stat.channel_reserve_msat; @@ -5980,10 +5982,10 @@ fn test_fail_holding_cell_htlc_upon_free() { assert_eq!(chan_stat.holding_cell_outbound_amount_msat, max_can_send); // Flush the pending fee update. - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let (as_revoke_and_ack, _) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &as_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &as_revoke_and_ack); check_added_monitors!(nodes[0], 1); // Upon receipt of the RAA, there will be an attempt to resend the holding cell @@ -6042,7 +6044,7 @@ fn test_free_and_fail_holding_cell_htlcs() { _ => panic!("Unexpected event"), }; - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_msg.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_msg.unwrap()); let mut chan_stat = get_channel_value_stat!(nodes[0], nodes[1], chan.2); let channel_reserve = chan_stat.channel_reserve_msat; @@ -6067,11 +6069,11 @@ fn test_free_and_fail_holding_cell_htlcs() { assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1 + amt_2); // Flush the pending fee update. - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), commitment_signed); let (revoke_and_ack, commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &revoke_and_ack); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &revoke_and_ack); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed); check_added_monitors!(nodes[0], 2); // Upon receipt of the RAA, there will be an attempt to resend the holding cell HTLCs, @@ -6110,9 +6112,9 @@ fn test_free_and_fail_holding_cell_htlcs() { MessageSendEvent::SendRevokeAndACK { msg, .. } => msg, _ => panic!("Unexpected event"), }; - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); let events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -6132,7 +6134,7 @@ fn test_free_and_fail_holding_cell_htlcs() { expect_payment_claimed!(nodes[1], payment_hash_1, amt_1); let update_msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_msgs.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_msgs.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], update_msgs.commitment_signed, false, true); expect_payment_sent!(nodes[0], payment_preimage_1); } @@ -6172,7 +6174,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { _ => panic!("Unexpected event"), }; - nodes[2].node.handle_update_fee(&nodes[1].node.get_our_node_id(), update_msg.unwrap()); + nodes[2].node.handle_update_fee(nodes[1].node.get_our_node_id(), update_msg.unwrap()); let mut chan_stat = get_channel_value_stat!(nodes[0], nodes[1], chan_0_1.2); let channel_reserve = chan_stat.channel_reserve_msat; @@ -6192,7 +6194,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -6201,11 +6203,11 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { assert_eq!(chan_stat.holding_cell_outbound_amount_msat, max_can_send); // Flush the pending fee update. - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), commitment_signed); let (raa, commitment_signed) = get_revoke_commit_msgs!(nodes[2], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[2], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &raa); - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &commitment_signed); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &raa); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &commitment_signed); check_added_monitors!(nodes[1], 2); // A final RAA message is generated to finalize the fee update. @@ -6219,7 +6221,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { _ => panic!("Unexpected event"), }; - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa_msg); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa_msg); check_added_monitors!(nodes[2], 1); assert!(nodes[2].node.get_and_clear_pending_msg_events().is_empty()); @@ -6250,14 +6252,14 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { }; // Pass the failure messages back to nodes[0]. - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &commitment_signed); // Complete the HTLC failure+removal process. let (raa, commitment_signed) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &commitment_signed); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &commitment_signed); check_added_monitors!(nodes[1], 2); let final_raa_event = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(final_raa_event.len(), 1); @@ -6265,7 +6267,7 @@ fn test_fail_holding_cell_htlc_upon_free_multihop() { &MessageSendEvent::SendRevokeAndACK { ref msg, .. } => msg.clone(), _ => panic!("Unexpected event"), }; - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa); expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_1_2.0.contents.short_channel_id, false); check_added_monitors!(nodes[0], 1); } @@ -6352,7 +6354,7 @@ fn test_update_add_htlc_bolt2_receiver_zero_value_msat() { let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = 0; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Remote side tried to send a 0-msat HTLC", 3); check_closed_broadcast!(nodes[1], true).unwrap(); check_added_monitors!(nodes[1], 1); @@ -6411,7 +6413,7 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_num_and_htlc_id_increment() } SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); @@ -6473,7 +6475,7 @@ fn test_update_add_htlc_bolt2_receiver_check_amount_received_more_than_min() { check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = htlc_minimum_msat-1; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); assert!(regex::Regex::new(r"Remote side tried to send less than our minimum HTLC value\. Lower limit: \(\d+\)\. Actual: \(\d+\)").unwrap().is_match(err_msg.data.as_str())); @@ -6508,7 +6510,7 @@ fn test_update_add_htlc_bolt2_receiver_sender_can_afford_amount_sent() { // at this time channel-initiatee receivers are not required to enforce that senders // respect the fee_spike_reserve. updates.update_add_htlcs[0].amount_msat = max_can_send + commit_tx_fee_outbound + 1; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); @@ -6552,10 +6554,10 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() { for i in 0..50 { msg.htlc_id = i as u64; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &msg); } msg.htlc_id = (50) as u64; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &msg); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); @@ -6579,7 +6581,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() { check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].amount_msat = get_channel_value_stat!(nodes[1], nodes[0], chan.2).counterparty_max_htlc_value_in_flight_msat + 1; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); @@ -6603,7 +6605,7 @@ fn test_update_add_htlc_bolt2_receiver_check_cltv_expiry() { check_added_monitors!(nodes[0], 1); let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].cltv_expiry = 500000000; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); @@ -6628,34 +6630,34 @@ fn test_update_add_htlc_bolt2_receiver_check_repeated_id_ignore() { RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); //Disconnect and Reconnect - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 1); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 1); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); handle_chan_reestablish_msgs!(nodes[1], nodes[0]); //Resend HTLC - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert_eq!(updates.commitment_signed.htlc_signatures.len(), 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[1], 1); let _bs_responses = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); assert!(nodes[1].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[1], true).unwrap(); @@ -6679,7 +6681,7 @@ fn test_update_fulfill_htlc_bolt2_update_fulfill_htlc_before_commitment() { check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let update_msg = msgs::UpdateFulfillHTLC{ channel_id: chan.2, @@ -6687,7 +6689,7 @@ fn test_update_fulfill_htlc_bolt2_update_fulfill_htlc_before_commitment() { payment_preimage: our_payment_preimage, }; - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_msg); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6711,7 +6713,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() { RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let update_msg = msgs::UpdateFailHTLC{ channel_id: chan.2, @@ -6719,7 +6721,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_htlc_before_commitment() { reason: msgs::OnionErrorPacket { data: Vec::new()}, }; - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6743,7 +6745,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_malformed_htlc_before_commitment() RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); let update_msg = msgs::UpdateFailMalformedHTLC{ channel_id: chan.2, htlc_id: 0, @@ -6751,7 +6753,7 @@ fn test_update_fulfill_htlc_bolt2_update_fail_malformed_htlc_before_commitment() failure_code: 0x8000, }; - nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg); + nodes[0].node.handle_update_fail_malformed_htlc(nodes[1].node.get_our_node_id(), &update_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6794,7 +6796,7 @@ fn test_update_fulfill_htlc_bolt2_incorrect_htlc_id() { update_fulfill_msg.htlc_id = 1; - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6837,7 +6839,7 @@ fn test_update_fulfill_htlc_bolt2_wrong_preimage() { update_fulfill_msg.payment_preimage = PaymentPreimage([1; 32]); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_msg); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6864,7 +6866,7 @@ fn test_update_fulfill_htlc_bolt2_missing_badonion_bit_for_malformed_htlc_messag let mut updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); updates.update_add_htlcs[0].onion_routing_packet.version = 1; //Produce a malformed HTLC message - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], updates.commitment_signed, false, true); @@ -6884,7 +6886,7 @@ fn test_update_fulfill_htlc_bolt2_missing_badonion_bit_for_malformed_htlc_messag } }; update_msg.failure_code &= !0x8000; - nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_msg); + nodes[0].node.handle_update_fail_malformed_htlc(nodes[1].node.get_our_node_id(), &update_msg); assert!(nodes[0].node.list_channels().is_empty()); let err_msg = check_closed_broadcast!(nodes[0], true).unwrap(); @@ -6916,7 +6918,7 @@ fn test_update_fulfill_htlc_bolt2_after_malformed_htlc_message_must_forward_upda assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -6928,7 +6930,7 @@ fn test_update_fulfill_htlc_bolt2_after_malformed_htlc_message_must_forward_upda //Second Hop payment_event.msgs[0].onion_routing_packet.version = 1; //Produce a malformed HTLC message - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[2], 0); commitment_signed_dance!(nodes[2], nodes[1], payment_event.commitment_msg, false, true); @@ -6948,7 +6950,7 @@ fn test_update_fulfill_htlc_bolt2_after_malformed_htlc_message_must_forward_upda } }; - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), &update_msg.0); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), &update_msg.0); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[2], update_msg.1, false, true); @@ -6990,7 +6992,7 @@ fn test_channel_failed_after_message_with_badonion_node_perm_bits_set() { SendEvent::from_node(&nodes[0]) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors!(nodes[1], 1); @@ -6999,7 +7001,7 @@ fn test_channel_failed_after_message_with_badonion_node_perm_bits_set() { // Second Hop payment_event.msgs[0].onion_routing_packet.version = 1; // Trigger an invalid_onion_version error - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[2], 0); commitment_signed_dance!(nodes[2], nodes[1], payment_event.commitment_msg, false, true); @@ -7011,7 +7013,7 @@ fn test_channel_failed_after_message_with_badonion_node_perm_bits_set() { // Set the NODE bit (BADONION and PERM already set in invalid_onion_version error) update_msg.failure_code |= 0x2000; - nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), &update_msg); + nodes[1].node.handle_update_fail_malformed_htlc(nodes[2].node.get_our_node_id(), &update_msg); commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, false, true); }, _ => panic!("Unexpected event"), @@ -7026,7 +7028,7 @@ fn test_channel_failed_after_message_with_badonion_node_perm_bits_set() { match events_4[0] { MessageSendEvent::UpdateHTLCs { ref updates, .. } => { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false, true); }, _ => panic!("Unexpected event"), @@ -7086,8 +7088,8 @@ fn do_test_failure_delay_dust_htlc_local_commitment(announce_latest: bool) { check_added_monitors!(nodes[1], 1); let remove = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &remove.update_fail_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &remove.commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &remove.update_fail_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &remove.commitment_signed); check_added_monitors!(nodes[0], 1); // Cache one local commitment tx as lastest @@ -7276,10 +7278,10 @@ fn test_user_configurable_csv_delay() { // We test msg.to_self_delay <= config.their_to_self_delay is enforced in Chanel::accept_channel() nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1000000, 1000000, 42, None, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); accept_channel.common_fields.to_self_delay = 200; - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let reason_msg; if let MessageSendEvent::HandleError { ref action, .. } = nodes[0].node.get_and_clear_pending_msg_events()[0] { match action { @@ -7340,7 +7342,7 @@ fn test_check_htlc_underpaying() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // Note that we first have to wait a random delay before processing the receipt of the HTLC, @@ -7367,7 +7369,7 @@ fn test_check_htlc_underpaying() { }; check_added_monitors!(nodes[1], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlc); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlc); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false, true); // 10_000 msat as u64, followed by a height of CHAN_CONFIRM_DEPTH as u32 @@ -7394,8 +7396,8 @@ fn test_announce_disable_channels() { create_announced_chan_between_nodes(&nodes, 0, 1); // Disconnect peers - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); for _ in 0..DISABLE_GOSSIP_TICKS + 1 { nodes[0].node.timer_tick_occurred(); @@ -7416,31 +7418,31 @@ fn test_announce_disable_channels() { } } // Reconnect peers - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); assert_eq!(reestablish_1.len(), 3); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); assert_eq!(reestablish_2.len(), 3); // Reestablish chan_1 - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); handle_chan_reestablish_msgs!(nodes[1], nodes[0]); // Reestablish chan_2 - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[1]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[1]); handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[1]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[1]); handle_chan_reestablish_msgs!(nodes[1], nodes[0]); // Reestablish chan_3 - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[2]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[2]); handle_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[2]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[2]); handle_chan_reestablish_msgs!(nodes[1], nodes[0]); for _ in 0..ENABLE_GOSSIP_TICKS { @@ -7668,8 +7670,8 @@ fn test_bump_penalty_txn_on_revoked_htlcs() { assert_ne!(node_txn[0].input[0].previous_output, node_txn[2].input[0].previous_output); assert_ne!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output); - assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output); - assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output); + assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output); + assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output); // node_txn[3] spends the revoked outputs from the revoked_htlc_txn (which only have one // output, checked above). @@ -7871,7 +7873,7 @@ fn test_counterparty_raa_skip_no_crash() { &SecretKey::from_slice(&keys.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER - 2).unwrap()).unwrap()); } - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &msgs::RevokeAndACK { channel_id, per_commitment_secret, @@ -8003,7 +8005,7 @@ fn test_override_0msat_htlc_minimum() { let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert_eq!(res.common_fields.htlc_minimum_msat, 1); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &res); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &res); let res = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); assert_eq!(res.common_fields.htlc_minimum_msat, 1); } @@ -8072,7 +8074,7 @@ fn test_manually_accept_inbound_channel_request() { let temp_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, Some(manually_accept_conf)).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &res); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &res); // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in `msg_events` before // accepting the inbound channel request. @@ -8122,7 +8124,7 @@ fn test_manually_reject_inbound_channel_request() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, Some(manually_accept_conf)).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &res); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &res); // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in `msg_events` before // rejecting the inbound channel request. @@ -8162,7 +8164,7 @@ fn test_can_not_accept_inbound_channel_twice() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, Some(manually_accept_conf)).unwrap(); let res = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &res); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &res); // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in `msg_events` before // accepting the inbound channel request. @@ -8291,7 +8293,7 @@ fn test_onion_value_mpp_set_calculation() { payment_event.msgs[0].onion_routing_packet = new_onion_packet; } - node.node.handle_update_add_htlc(&prev_node.node.get_our_node_id(), &payment_event.msgs[0]); + node.node.handle_update_add_htlc(prev_node.node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(node, 0); commitment_signed_dance!(node, prev_node, payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(node); @@ -8439,7 +8441,7 @@ fn test_preimage_storage() { check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); } // Note that after leaving the above scope we have no knowledge of any arguments or return @@ -8482,7 +8484,7 @@ fn test_bad_secret_hash() { check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_msg_events(); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // We have to forward pending HTLCs once to process the receipt of the HTLC and then @@ -8495,7 +8497,7 @@ fn test_bad_secret_hash() { let mut events = nodes[1].node.get_and_clear_pending_msg_events(); match events.pop().unwrap() { MessageSendEvent::UpdateHTLCs { node_id: _, updates: msgs::CommitmentUpdate { update_fail_htlcs, commitment_signed, .. } } => { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false); }, _ => panic!("Unexpected event"), @@ -8581,7 +8583,7 @@ fn test_update_err_monitor_lockdown() { let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); { let mut node_0_per_peer_lock; let mut node_0_peer_state_lock; @@ -8683,7 +8685,7 @@ fn test_concurrent_monitor_claim() { let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(updates.update_add_htlcs.len(), 1); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &updates.update_add_htlcs[0]); { let mut node_0_per_peer_lock; let mut node_0_peer_state_lock; @@ -8748,9 +8750,9 @@ fn test_pre_lockin_no_chan_closed_update() { // Create an initial channel nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); let accept_chan_msg = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_chan_msg); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_chan_msg); // Move the first channel through the funding flow... let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); @@ -8760,7 +8762,7 @@ fn test_pre_lockin_no_chan_closed_update() { let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); let channel_id = ChannelId::v1_from_funding_outpoint(crate::chain::transaction::OutPoint { txid: funding_created_msg.funding_txid, index: funding_created_msg.funding_output_index }); - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id, data: "Hi".to_owned() }); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id, data: "Hi".to_owned() }); assert!(nodes[0].chain_monitor.added_monitors.lock().unwrap().is_empty()); check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("Hi".to_string()) }, true, [nodes[1].node.get_our_node_id()], 100000); @@ -8893,7 +8895,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain assert!(carol_updates.update_fee.is_none()); assert_eq!(carol_updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &carol_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &carol_updates.update_fulfill_htlcs[0]); let went_onchain = go_onchain_before_fulfill || force_closing_node == 1; expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], if went_onchain { None } else { Some(1000) }, went_onchain, false); // If Alice broadcasted but Bob doesn't know yet, here he prepares to tell her about the preimage. @@ -8907,7 +8909,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain _ => panic!("Unexpected event"), }; } - nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &carol_updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[2].node.get_our_node_id(), &carol_updates.commitment_signed); // One monitor update for the preimage to update the Bob<->Alice channel, one monitor update // Carol<->Bob's updated commitment transaction info. check_added_monitors!(nodes[1], 2); @@ -8929,9 +8931,9 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain _ => panic!("Unexpected event"), }; - nodes[2].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bob_revocation); + nodes[2].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bob_revocation); check_added_monitors!(nodes[2], 1); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bob_updates.commitment_signed); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bob_updates.commitment_signed); check_added_monitors!(nodes[2], 1); let events = nodes[2].node.get_and_clear_pending_msg_events(); @@ -8943,7 +8945,7 @@ fn do_test_onchain_htlc_settlement_after_close(broadcast_alice: bool, go_onchain }, _ => panic!("Unexpected event"), }; - nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &carol_revocation); + nodes[1].node.handle_revoke_and_ack(nodes[2].node.get_our_node_id(), &carol_revocation); check_added_monitors!(nodes[1], 1); // If this test requires the force-closed channel to not be on-chain until after the fulfill, @@ -9029,7 +9031,7 @@ fn test_duplicate_temporary_channel_id_from_different_peers() { // Assert that `nodes[0]` can accept both `OpenChannel` requests, even though they use the same // `temporary_channel_id` as they are from different peers. - nodes[0].node.handle_open_channel(&nodes[1].node.get_our_node_id(), &open_chan_msg_chan_1_0); + nodes[0].node.handle_open_channel(nodes[1].node.get_our_node_id(), &open_chan_msg_chan_1_0); { let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9042,7 +9044,7 @@ fn test_duplicate_temporary_channel_id_from_different_peers() { } } - nodes[0].node.handle_open_channel(&nodes[2].node.get_our_node_id(), &open_chan_msg_chan_2_0); + nodes[0].node.handle_open_channel(nodes[2].node.get_our_node_id(), &open_chan_msg_chan_2_0); { let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9087,7 +9089,7 @@ fn test_peer_funding_sidechannel() { nodes[2].node.funding_transaction_generated_unchecked(temp_chan_id_ca, nodes[0].node.get_our_node_id(), tx.clone(), funding_output.index).unwrap(); let funding_created_msg = get_event_msg!(nodes[2], MessageSendEvent::SendFundingCreated, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_created(&nodes[2].node.get_our_node_id(), &funding_created_msg); + nodes[0].node.handle_funding_created(nodes[2].node.get_our_node_id(), &funding_created_msg); get_event_msg!(nodes[0], MessageSendEvent::SendFundingSigned, nodes[2].node.get_our_node_id()); expect_channel_pending_event(&nodes[0], &nodes[2].node.get_our_node_id()); check_added_monitors!(nodes[0], 1); @@ -9100,14 +9102,14 @@ fn test_peer_funding_sidechannel() { // SendFundingCreated. However, when the peer responds with a funding_signed it will send the // appropriate error message. let as_funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &as_funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &as_funding_created); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let reason = ClosureReason::ProcessingError { err: format!("An existing channel using outpoint {} is open with peer {}", funding_output, nodes[2].node.get_our_node_id()), }; check_closed_events(&nodes[0], &[ExpectedCloseEvent::from_id_reason(ChannelId::v1_from_funding_outpoint(funding_output), true, reason)]); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); get_err_msg(&nodes[0], &nodes[1].node.get_our_node_id()); } @@ -9137,12 +9139,12 @@ fn test_duplicate_conflicting_funding_from_second_peer() { nodes[0].node.funding_transaction_generated(temp_chan_id, nodes[1].node.get_our_node_id(), tx.clone()).unwrap(); let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); // At this point, the channel should be closed, after having generated one monitor write (the // watch_channel call which failed), but zero monitor updates. check_added_monitors!(nodes[0], 1); @@ -9171,10 +9173,10 @@ fn test_duplicate_funding_err_in_funding() { let mut open_chan_msg = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); let node_c_temp_chan_id = open_chan_msg.common_fields.temporary_channel_id; open_chan_msg.common_fields.temporary_channel_id = real_channel_id; - nodes[1].node.handle_open_channel(&nodes[2].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[2].node.get_our_node_id(), &open_chan_msg); let mut accept_chan_msg = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[2].node.get_our_node_id()); accept_chan_msg.common_fields.temporary_channel_id = node_c_temp_chan_id; - nodes[2].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_chan_msg); + nodes[2].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_chan_msg); // Now that we have a second channel with the same funding txo, send a bogus funding message // and let nodes[1] remove the inbound channel. @@ -9186,7 +9188,7 @@ fn test_duplicate_funding_err_in_funding() { funding_created_msg.temporary_channel_id = real_channel_id; // Make the signature invalid by changing the funding output funding_created_msg.funding_output_index += 10; - nodes[1].node.handle_funding_created(&nodes[2].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[2].node.get_our_node_id(), &funding_created_msg); get_err_msg(&nodes[1], &nodes[2].node.get_our_node_id()); let err = "Invalid funding_created signature from peer".to_owned(); let reason = ClosureReason::ProcessingError { err }; @@ -9216,12 +9218,12 @@ fn test_duplicate_chan_id() { // Create an initial channel nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); // Try to create a second channel with the same temporary_channel_id as the first and check // that it is rejected. - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); { let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9245,7 +9247,7 @@ fn test_duplicate_chan_id() { check_added_monitors!(nodes[0], 0); let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msg); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msg); { let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -9266,7 +9268,7 @@ fn test_duplicate_chan_id() { // Technically this is allowed by the spec, but we don't support it and there's little reason // to. Still, it shouldn't cause any other issues. open_chan_msg.common_fields.temporary_channel_id = channel_id; - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_msg); { let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -9284,8 +9286,8 @@ fn test_duplicate_chan_id() { // Now try to create a second channel which has a duplicate funding output. nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let open_chan_2_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_2_msg); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_chan_2_msg); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); // Get and check the FundingGenerationReady event let funding_created = { @@ -9304,7 +9306,7 @@ fn test_duplicate_chan_id() { }.unwrap() }; check_added_monitors!(nodes[0], 0); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); // At this point we'll look up if the channel_id is present and immediately fail the channel // without trying to persist the `ChannelMonitor`. check_added_monitors!(nodes[1], 0); @@ -9332,7 +9334,7 @@ fn test_duplicate_chan_id() { // finally, finish creating the original channel and send a payment over it to make sure // everything is functional. - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); { let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -9375,11 +9377,11 @@ fn test_error_chans_closed() { assert_eq!(nodes[2].node.list_usable_channels().len(), 1); // Closing a channel from a different peer has no effect - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: chan_3.2, data: "ERR".to_owned() }); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: chan_3.2, data: "ERR".to_owned() }); assert_eq!(nodes[0].node.list_usable_channels().len(), 3); // Closing one channel doesn't impact others - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: chan_2.2, data: "ERR".to_owned() }); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: chan_2.2, data: "ERR".to_owned() }); check_added_monitors!(nodes[0], 1); check_closed_broadcast!(nodes[0], false); check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("ERR".to_string()) }, @@ -9391,7 +9393,7 @@ fn test_error_chans_closed() { // A null channel ID should close all channels let _chan_4 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001); - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: ChannelId::new_zero(), data: "ERR".to_owned() }); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: ChannelId::new_zero(), data: "ERR".to_owned() }); check_added_monitors!(nodes[0], 2); check_closed_event!(nodes[0], 2, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString("ERR".to_string()) }, [nodes[1].node.get_our_node_id(); 2], 100000); @@ -9414,7 +9416,7 @@ fn test_error_chans_closed() { assert_eq!(nodes[0].node.list_usable_channels().len(), 1); assert!(nodes[0].node.list_usable_channels()[0].channel_id == chan_3.2); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); assert_eq!(nodes[0].node.list_usable_channels().len(), 1); assert!(nodes[0].node.list_usable_channels()[0].channel_id == chan_3.2); } @@ -9437,8 +9439,8 @@ fn test_invalid_funding_tx() { let nodes = create_network(2, &node_cfgs, &node_chanmgrs); nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 10_000, 42, None, None).unwrap(); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id())); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42); @@ -9454,11 +9456,11 @@ fn test_invalid_funding_tx() { } nodes[0].node.funding_transaction_generated_unchecked(temporary_channel_id, nodes[1].node.get_our_node_id(), tx.clone(), 0).unwrap(); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); @@ -9524,10 +9526,10 @@ fn test_coinbase_funding_tx() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); // Create the coinbase funding transaction. let (temporary_channel_id, tx, _) = create_coinbase_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); @@ -9536,13 +9538,13 @@ fn test_coinbase_funding_tx() { check_added_monitors!(nodes[0], 0); let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); @@ -9557,7 +9559,7 @@ fn test_coinbase_funding_tx() { // Now connect one more block which results in 100 confirmations of the coinbase transaction. connect_blocks(&nodes[0], 1); // There should now be a `channel_ready` which can be handled. - let _ = &nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &get_event_msg!(&nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); + let _ = &nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &get_event_msg!(&nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); confirm_transaction_at(&nodes[1], &tx, 1); connect_blocks(&nodes[1], COINBASE_MATURITY - 2); @@ -9593,8 +9595,8 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t create_announced_chan_between_nodes(&nodes, 0, 1); let (chan_announce, _, channel_id, _) = create_announced_chan_between_nodes(&nodes, 1, 2); let (_, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000); - nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); let error_message = "Channel force-closed"; nodes[1].node.force_close_broadcasting_latest_txn(&channel_id, &nodes[2].node.get_our_node_id(), error_message.to_string()).unwrap(); check_closed_broadcast!(nodes[1], true); @@ -9643,7 +9645,7 @@ fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_t assert_eq!(updates.update_fail_htlcs.len(), 1); assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true); expect_payment_failed_with_update!(nodes[0], payment_hash, false, chan_announce.contents.short_channel_id, true); } @@ -9676,7 +9678,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); } expect_pending_htlcs_forwardable!(nodes[1]); @@ -9690,7 +9692,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // At this point, nodes[1] would notice it has too much value for the payment. It will // assume the second is a privacy attack (no longer particularly relevant @@ -9716,8 +9718,8 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) { let fail_updates_1 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(fail_updates_1.update_fail_htlcs.len(), 2); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[1]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[1]); commitment_signed_dance!(nodes[0], nodes[1], fail_updates_1.commitment_signed, false); let failure_events = nodes[0].node.get_and_clear_pending_events(); @@ -9733,7 +9735,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) { check_added_monitors!(nodes[1], 1); let fail_updates_1 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], fail_updates_1.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], our_payment_hash, true, PaymentFailedConditions::new()); @@ -9816,7 +9818,7 @@ fn test_inconsistent_mpp_params() { assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -9826,7 +9828,7 @@ fn test_inconsistent_mpp_params() { assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[3].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[3].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[3], 0); commitment_signed_dance!(nodes[3], nodes[2], payment_event.commitment_msg, true, true); @@ -9842,14 +9844,14 @@ fn test_inconsistent_mpp_params() { check_added_monitors!(nodes[3], 1); let fail_updates_1 = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); commitment_signed_dance!(nodes[2], nodes[3], fail_updates_1.commitment_signed, false); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }]); check_added_monitors!(nodes[2], 1); let fail_updates_2 = get_htlc_update_msgs!(nodes[2], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &fail_updates_2.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &fail_updates_2.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], fail_updates_2.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], our_payment_hash, true, PaymentFailedConditions::new().mpp_parts_remain()); @@ -9990,9 +9992,9 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e if on_holder_tx { open_channel.common_fields.dust_limit_satoshis = 546; } - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let channel_type_features = ChannelTypeFeatures::only_static_remote_key(); @@ -10010,11 +10012,11 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e } nodes[0].node.funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), tx.clone()).unwrap(); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id())); check_added_monitors!(nodes[0], 1); expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id()); @@ -10113,7 +10115,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e let mut events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.remove(0)); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); // With default dust exposure: 5000 sats if on_holder_tx { // Outbound dust balance: 6399 sats @@ -10250,7 +10252,7 @@ fn test_nondust_htlc_fees_are_dust() { check_added_monitors(&nodes[2], 1); let send = SendEvent::from_node(&nodes[2]); - nodes[0].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &send.msgs[0]); + nodes[0].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &send.msgs[0]); commitment_signed_dance!(nodes[0], nodes[2], send.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[0]); @@ -10262,7 +10264,7 @@ fn test_nondust_htlc_fees_are_dust() { ); let fail = get_htlc_update_msgs(&nodes[0], &nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[0].node.get_our_node_id(), &fail.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[0].node.get_our_node_id(), &fail.update_fail_htlcs[0]); commitment_signed_dance!(nodes[2], nodes[0], fail.commitment_signed, false); expect_payment_failed_conditions(&nodes[2], payment_hash, false, PaymentFailedConditions::new()); } @@ -10277,9 +10279,9 @@ fn test_non_final_funding_tx() { let temp_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_message); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_message); let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel_message); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel_message); let best_height = nodes[0].node.best_block.read().unwrap().height; @@ -10317,9 +10319,9 @@ fn test_non_final_funding_tx_within_headroom() { let temp_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_message); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_message); let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel_message); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel_message); let best_height = nodes[0].node.best_block.read().unwrap().height; @@ -10372,7 +10374,7 @@ fn accept_busted_but_better_fee() { assert_eq!(events.len(), 1); match events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => { - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); commitment_signed_dance!(nodes[1], nodes[0], commitment_signed, false); }, _ => panic!("Unexpected event"), @@ -10391,7 +10393,7 @@ fn accept_busted_but_better_fee() { assert_eq!(events.len(), 1); match events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, ref commitment_signed, .. }, .. } => { - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); commitment_signed_dance!(nodes[1], nodes[0], commitment_signed, false); }, _ => panic!("Unexpected event"), @@ -10410,7 +10412,7 @@ fn accept_busted_but_better_fee() { assert_eq!(events.len(), 1); match events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { ref update_fee, .. }, .. } => { - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), update_fee.as_ref().unwrap()); check_closed_event!(nodes[1], 1, ClosureReason::PeerFeerateTooLow { peer_feerate_sat_per_kw: 1000, required_feerate_sat_per_kw: 5000, }, [nodes[0].node.get_our_node_id()], 100000); @@ -10449,7 +10451,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -10464,7 +10466,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash check_added_monitors!(nodes[1], 1); let fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], fail_updates.commitment_signed, false, true); expect_payment_failed!(nodes[0], payment_hash, true); @@ -10532,15 +10534,15 @@ fn test_disconnects_peer_awaiting_response_ticks() { nodes[0].node.timer_tick_occurred(); check_added_monitors!(&nodes[0], 1); let alice_fee_update = get_htlc_update_msgs(&nodes[0], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), alice_fee_update.update_fee.as_ref().unwrap()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &alice_fee_update.commitment_signed); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), alice_fee_update.update_fee.as_ref().unwrap()); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &alice_fee_update.commitment_signed); check_added_monitors!(&nodes[1], 1); // This will prompt Bob (nodes[1]) to respond with his `CommitmentSigned` and `RevokeAndACK`. let (bob_revoke_and_ack, bob_commitment_signed) = get_revoke_commit_msgs!(&nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bob_revoke_and_ack); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bob_revoke_and_ack); check_added_monitors!(&nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bob_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bob_commitment_signed); check_added_monitors(&nodes[0], 1); // Alice then needs to send her final `RevokeAndACK` to complete the commitment dance. We @@ -10553,16 +10555,16 @@ fn test_disconnects_peer_awaiting_response_ticks() { // // Note that since the commitment dance didn't complete above, Alice is expected to resend her // final `RevokeAndACK` to Bob to complete it. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let bob_init = msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }; - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &bob_init, true).unwrap(); + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &bob_init, true).unwrap(); let alice_init = msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }; - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &alice_init, true).unwrap(); + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &alice_init, true).unwrap(); // Upon reconnection, Alice sends her `ChannelReestablish` to Bob. Alice, however, hasn't // received Bob's yet, so she should disconnect him after reaching @@ -10570,7 +10572,7 @@ fn test_disconnects_peer_awaiting_response_ticks() { let alice_channel_reestablish = get_event_msg!( nodes[0], MessageSendEvent::SendChannelReestablish, nodes[1].node.get_our_node_id() ); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &alice_channel_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &alice_channel_reestablish); check_disconnect(&nodes[0]); // Bob now sends his `ChannelReestablish` to Alice to resume the channel and consider it "live". @@ -10582,7 +10584,7 @@ fn test_disconnects_peer_awaiting_response_ticks() { None } ).unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bob_channel_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bob_channel_reestablish); // Sanity check that Alice won't disconnect Bob since she's no longer waiting for any messages. for _ in 0..DISCONNECT_PEER_AWAITING_RESPONSE_TICKS { @@ -10595,7 +10597,7 @@ fn test_disconnects_peer_awaiting_response_ticks() { check_disconnect(&nodes[1]); // Finally, have Bob process the last message. - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &alice_revoke_and_ack); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &alice_revoke_and_ack); check_added_monitors(&nodes[1], 1); // At this point, neither node should attempt to disconnect each other, since they aren't @@ -10617,9 +10619,9 @@ fn test_remove_expired_outbound_unfunded_channels() { let temp_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_message); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_message); let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel_message); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel_message); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -10668,9 +10670,9 @@ fn test_remove_expired_inbound_unfunded_channels() { let temp_channel_id = nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_message = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_message); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_message); let accept_channel_message = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel_message); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel_message); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -10725,8 +10727,8 @@ fn test_channel_close_when_not_timely_accepted() { let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert_eq!(open_channel_msg.common_fields.temporary_channel_id, create_chan_id); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Make sure that we have not removed the OutboundV1Channel from node[0] immediately. assert_eq!(nodes[0].node.list_channels().len(), 1); @@ -10768,8 +10770,8 @@ fn test_rebroadcast_open_channel_when_reconnect_mid_handshake() { let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert_eq!(open_channel_msg.common_fields.temporary_channel_id, create_chan_id); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Make sure that we have not removed the OutboundV1Channel from node[0] immediately. assert_eq!(nodes[0].node.list_channels().len(), 1); @@ -10778,10 +10780,10 @@ fn test_rebroadcast_open_channel_when_reconnect_mid_handshake() { assert_eq!(nodes[1].node.list_channels().len(), 0); // The peers now reconnect - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); @@ -10828,7 +10830,7 @@ fn do_test_multi_post_event_actions(do_reload: bool) { for dest in &[1, 2] { let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[*dest], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[*dest].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[*dest].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[*dest], htlc_fulfill_updates.commitment_signed, false); check_added_monitors(&nodes[0], 0); } @@ -10841,8 +10843,8 @@ fn do_test_multi_post_event_actions(do_reload: bool) { check_added_monitors(&nodes[1], 1); let send_event = SendEvent::from_node(&nodes[1]); - nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event.msgs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event.commitment_msg); + nodes[0].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_event.msgs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &send_event.commitment_msg); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); if do_reload { @@ -10851,8 +10853,8 @@ fn do_test_multi_post_event_actions(do_reload: bool) { let chan_1_monitor_serialized = get_monitor!(nodes[0], chan_id_2).encode(); reload_node!(nodes[0], test_default_channel_config(), &nodes_0_serialized, &[&chan_0_monitor_serialized, &chan_1_monitor_serialized], persister, chain_monitor, nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[0].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[2])); @@ -10895,25 +10897,25 @@ fn test_batch_channel_open() { ]); // Go through the funding_created and funding_signed flow with node 1. - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); check_added_monitors(&nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // The transaction should not have been broadcast before all channels are ready. assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().len(), 0); // Go through the funding_created and funding_signed flow with node 2. - nodes[2].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[1]); + nodes[2].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[1]); check_added_monitors(&nodes[2], 1); expect_channel_pending_event(&nodes[2], &nodes[0].node.get_our_node_id()); let funding_signed_msg = get_event_msg!(nodes[2], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_funding_signed(&nodes[2].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[2].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // The transaction should not have been broadcast before persisting all monitors has been @@ -10965,12 +10967,12 @@ fn test_close_in_funding_batch() { ]); // Go through the funding_created and funding_signed flow with node 1. - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); check_added_monitors(&nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // The transaction should not have been broadcast before all channels are ready. @@ -11044,22 +11046,22 @@ fn test_batch_funding_close_after_funding_signed() { ]); // Go through the funding_created and funding_signed flow with node 1. - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); check_added_monitors(&nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // Go through the funding_created and funding_signed flow with node 2. - nodes[2].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[1]); + nodes[2].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[1]); check_added_monitors(&nodes[2], 1); expect_channel_pending_event(&nodes[2], &nodes[0].node.get_our_node_id()); let funding_signed_msg = get_event_msg!(nodes[2], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_funding_signed(&nodes[2].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[2].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // The transaction should not have been broadcast before all channels are ready. @@ -11194,7 +11196,7 @@ fn test_accept_inbound_channel_errors_queued() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).unwrap(); let open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); match events[0] { Event::OpenChannelRequest { temporary_channel_id, .. } => { @@ -11221,22 +11223,22 @@ fn test_manual_funding_abandon() { assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).is_ok()); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, _tx, funding_outpoint) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42); nodes[0].node.unsafe_manual_funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), funding_outpoint).unwrap(); check_added_monitors!(nodes[0], 0); let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); let err = msgs::ErrorMessage { channel_id: funding_signed.channel_id, data: "".to_string() }; - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &err); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &err); let close_events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(close_events.len(), 2); @@ -11263,21 +11265,21 @@ fn test_funding_signed_event() { assert!(nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 0, 42, None, None).is_ok()); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, funding_outpoint) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42); nodes[0].node.unsafe_manual_funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), funding_outpoint).unwrap(); check_added_monitors!(nodes[0], 0); let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); check_added_monitors!(nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed); check_added_monitors!(nodes[0], 1); let events = &nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 2); @@ -11299,9 +11301,9 @@ fn test_funding_signed_event() { mine_transaction(&nodes[1], &tx); let as_channel_ready = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); let as_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &as_channel_ready); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &as_channel_ready); expect_channel_ready_event(&nodes[0], &nodes[1].node.get_our_node_id()); expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id()); diff --git a/lightning/src/ln/interactivetxs.rs b/lightning/src/ln/interactivetxs.rs index deec638f7f1..15e911cbb4c 100644 --- a/lightning/src/ln/interactivetxs.rs +++ b/lightning/src/ln/interactivetxs.rs @@ -1328,7 +1328,7 @@ mod tests { impl EntropySource for TestEntropySource { fn get_secure_random_bytes(&self) -> [u8; 32] { let mut res = [0u8; 32]; - let increment = self.0.get_increment(); + let increment = self.0.next(); for (i, byte) in res.iter_mut().enumerate() { // Rotate the increment value by 'i' bits to the right, to avoid clashes // when `generate_local_serial_id` does a parity flip on consecutive calls for the diff --git a/lightning/src/ln/invoice_utils.rs b/lightning/src/ln/invoice_utils.rs index 71686df59ce..287f11df7ec 100644 --- a/lightning/src/ln/invoice_utils.rs +++ b/lightning/src/ln/invoice_utils.rs @@ -61,9 +61,8 @@ use core::iter::Iterator; /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash /// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels /// [`MIN_FINAL_CLTV_EXPIRY_DETLA`]: crate::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA -/// -/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not -/// available and the current time is supplied by the caller. +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")] pub fn create_phantom_invoice( amt_msat: Option, payment_hash: Option, description: String, invoice_expiry_delta_secs: u32, phantom_route_hints: Vec, entropy_source: ES, @@ -117,9 +116,8 @@ where /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash /// [`PhantomRouteHints::channels`]: crate::ln::channelmanager::PhantomRouteHints::channels -/// -/// This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not -/// available and the current time is supplied by the caller. +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")] pub fn create_phantom_invoice_with_description_hash( amt_msat: Option, payment_hash: Option, invoice_expiry_delta_secs: u32, description_hash: Sha256, phantom_route_hints: Vec, entropy_source: ES, @@ -399,9 +397,12 @@ where ) } -/// See [`create_invoice_from_channelmanager_with_description_hash`] -/// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not -/// available and the current time is supplied by the caller. +/// Utility to construct an invoice. Generally, unless you want to do something like a custom +/// `cltv_expiry`, this is what you should be using to create an invoice. +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager_with_description_hash`] for more information.")] +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "This can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")] pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_since_epoch( channelmanager: &ChannelManager, node_signer: NS, logger: L, network: Currency, amt_msat: Option, description_hash: Sha256, @@ -424,9 +425,12 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin ) } -/// See [`create_invoice_from_channelmanager`] -/// This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not -/// available and the current time is supplied by the caller. +/// Utility to construct an invoice. Generally, unless you want to do something like a custom +/// `cltv_expiry`, this is what you should be using to create an invoice. +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "See [`create_invoice_from_channelmanager`] for more information.")] +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "This version can be used in a `no_std` environment, where [`std::time::SystemTime`] is not available and the current time is supplied by the caller.")] pub fn create_invoice_from_channelmanager_and_duration_since_epoch( channelmanager: &ChannelManager, node_signer: NS, logger: L, network: Currency, amt_msat: Option, description: String, duration_since_epoch: Duration, @@ -906,8 +910,8 @@ mod test { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors(&nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); @@ -1009,19 +1013,19 @@ mod test { // yet announced. let pub_channel_scid = mine_transaction(&nodes[0], &conf_tx); let node_a_pub_channel_ready = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &node_a_pub_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &node_a_pub_channel_ready); assert_eq!(mine_transaction(&nodes[1], &conf_tx), pub_channel_scid); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); if let MessageSendEvent::SendChannelReady { msg, .. } = &events[0] { - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), msg); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), msg); } else { panic!(); } if let MessageSendEvent::SendChannelUpdate { msg, .. } = &events[1] { - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), msg); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), msg); } else { panic!(); } - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id())); expect_channel_ready_event(&nodes[0], &nodes[1].node.get_our_node_id()); expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id()); @@ -1094,13 +1098,13 @@ mod test { // With only one sufficient-value peer connected we should only get its hint scid_aliases.remove(&chan_b.0.short_channel_id_alias.unwrap()); - nodes[0].node.peer_disconnected(&nodes[2].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[2].node.get_our_node_id()); match_invoice_routes(Some(1_000_000_000), &nodes[0], scid_aliases.clone()); // If we don't have any sufficient-value peers connected we should get all hints with // sufficient value, even though there is a connected insufficient-value peer. scid_aliases.insert(chan_b.0.short_channel_id_alias.unwrap()); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); match_invoice_routes(Some(1_000_000_000), &nodes[0], scid_aliases); } @@ -1161,9 +1165,9 @@ mod test { private_chan_cfg.channel_handshake_config.announce_for_forwarding = false; let temporary_channel_id = nodes[2].node.create_channel(nodes[0].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None, Some(private_chan_cfg)).unwrap(); let open_channel = get_event_msg!(nodes[2], MessageSendEvent::SendOpenChannel, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_open_channel(&nodes[2].node.get_our_node_id(), &open_channel); + nodes[0].node.handle_open_channel(nodes[2].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[0], MessageSendEvent::SendAcceptChannel, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_accept_channel(&nodes[0].node.get_our_node_id(), &accept_channel); + nodes[2].node.handle_accept_channel(nodes[0].node.get_our_node_id(), &accept_channel); let tx = sign_funding_transaction(&nodes[2], &nodes[0], 1_000_000, temporary_channel_id); @@ -1173,9 +1177,9 @@ mod test { confirm_transaction_at(&nodes[0], &tx, conf_height); connect_blocks(&nodes[0], CHAN_CONFIRM_DEPTH - 1); let as_channel_ready = get_event_msg!(nodes[2], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id()); - nodes[2].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[2].node.get_our_node_id())); + nodes[2].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, nodes[2].node.get_our_node_id())); get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_channel_ready(&nodes[2].node.get_our_node_id(), &as_channel_ready); + nodes[0].node.handle_channel_ready(nodes[2].node.get_our_node_id(), &as_channel_ready); get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[2].node.get_our_node_id()); expect_channel_ready_event(&nodes[0], &nodes[2].node.get_our_node_id()); expect_channel_ready_event(&nodes[2], &nodes[0].node.get_our_node_id()); @@ -1197,8 +1201,8 @@ mod test { let _chan_1_0 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 0, 100000, 10001); let chan_2_0 = create_announced_chan_between_nodes_with_value(&nodes, 2, 0, 100000, 10001); - nodes[2].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_2_0.1); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan_2_0.0); + nodes[2].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_2_0.1); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan_2_0.0); // Ensure that the invoice doesn't include any route hints for any of `nodes[0]` channels, // even though all channels between `nodes[1]` and `nodes[0]` are private, as there is a @@ -1213,12 +1217,12 @@ mod test { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_1_0 = create_announced_chan_between_nodes_with_value(&nodes, 1, 0, 100000, 10001); - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan_1_0.0); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_1_0.1); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &chan_1_0.0); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_1_0.1); let chan_2_0 = create_announced_chan_between_nodes_with_value(&nodes, 2, 0, 100000, 10001); - nodes[2].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_2_0.1); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan_2_0.0); + nodes[2].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_2_0.1); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan_2_0.0); // As all of `nodes[0]` channels are public, no channels should be included in the hints match_invoice_routes(Some(5000), &nodes[0], HashSet::new()); @@ -1299,11 +1303,11 @@ mod test { let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); let nodes = create_network(3, &node_cfgs, &node_chanmgrs); let chan_0_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001); - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan_0_1.1); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_0_1.0); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &chan_0_1.1); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_0_1.0); let chan_0_2 = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 100000, 10001); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan_0_2.1); - nodes[2].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_0_2.0); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan_0_2.1); + nodes[2].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_0_2.0); let payment_amt = 10_000; let route_hints = vec![ @@ -1364,7 +1368,7 @@ mod test { }; (SendEvent::from_event(events.remove(0)), fwd_idx) }; - nodes[fwd_idx].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[fwd_idx].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[fwd_idx], nodes[0], &payment_event.commitment_msg, false, true); // Note that we have to "forward pending HTLCs" twice before we see the PaymentClaimable as @@ -1562,9 +1566,9 @@ mod test { private_chan_cfg.channel_handshake_config.announce_for_forwarding = false; let temporary_channel_id = nodes[1].node.create_channel(nodes[3].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None, Some(private_chan_cfg)).unwrap(); let open_channel = get_event_msg!(nodes[1], MessageSendEvent::SendOpenChannel, nodes[3].node.get_our_node_id()); - nodes[3].node.handle_open_channel(&nodes[1].node.get_our_node_id(), &open_channel); + nodes[3].node.handle_open_channel(nodes[1].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[3], MessageSendEvent::SendAcceptChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_accept_channel(&nodes[3].node.get_our_node_id(), &accept_channel); + nodes[1].node.handle_accept_channel(nodes[3].node.get_our_node_id(), &accept_channel); let tx = sign_funding_transaction(&nodes[1], &nodes[3], 1_000_000, temporary_channel_id); @@ -1574,9 +1578,9 @@ mod test { confirm_transaction_at(&nodes[3], &tx, conf_height); connect_blocks(&nodes[3], CHAN_CONFIRM_DEPTH - 1); let as_channel_ready = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[3].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[3].node.get_our_node_id(), &get_event_msg!(nodes[3], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_channel_ready(nodes[3].node.get_our_node_id(), &get_event_msg!(nodes[3], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[3].node.get_our_node_id()); - nodes[3].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &as_channel_ready); + nodes[3].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &as_channel_ready); get_event_msg!(nodes[3], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); expect_channel_ready_event(&nodes[1], &nodes[3].node.get_our_node_id()); expect_channel_ready_event(&nodes[3], &nodes[1].node.get_our_node_id()); @@ -1612,8 +1616,8 @@ mod test { let chan_0_1 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001); let chan_2_0 = create_announced_chan_between_nodes_with_value(&nodes, 2, 0, 100000, 10001); - nodes[2].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_2_0.1); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan_2_0.0); + nodes[2].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_2_0.1); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan_2_0.0); // Hints should include `chan_0_1` from as `nodes[1]` only have private channels, but not // `chan_0_2` as `nodes[2]` only has public channels. @@ -1642,8 +1646,8 @@ mod test { let nodes = create_network(4, &node_cfgs, &node_chanmgrs); let chan_0_2 = create_announced_chan_between_nodes_with_value(&nodes, 0, 2, 100000, 10001); - nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan_0_2.1); - nodes[2].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &chan_0_2.0); + nodes[0].node.handle_channel_update(nodes[2].node.get_our_node_id(), &chan_0_2.1); + nodes[2].node.handle_channel_update(nodes[0].node.get_our_node_id(), &chan_0_2.0); let _chan_1_2 = create_unannounced_chan_between_nodes_with_value(&nodes, 1, 2, 100000, 10001); let chan_0_3 = create_unannounced_chan_between_nodes_with_value(&nodes, 0, 3, 100000, 10001); diff --git a/lightning/src/ln/max_payment_path_len_tests.rs b/lightning/src/ln/max_payment_path_len_tests.rs index 69ae3cd7679..380fe21984b 100644 --- a/lightning/src/ln/max_payment_path_len_tests.rs +++ b/lightning/src/ln/max_payment_path_len_tests.rs @@ -255,6 +255,13 @@ fn blinded_path_with_custom_tlv() { create_announced_chan_between_nodes(&nodes, 1, 2); let chan_upd_2_3 = create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 1_000_000, 0).0.contents; + // Ensure all nodes are at the same height + let node_max_height = nodes.iter().map(|node| node.blocks.lock().unwrap().len()).max().unwrap() as u32; + connect_blocks(&nodes[0], node_max_height - nodes[0].best_block_info().1); + connect_blocks(&nodes[1], node_max_height - nodes[1].best_block_info().1); + connect_blocks(&nodes[2], node_max_height - nodes[2].best_block_info().1); + connect_blocks(&nodes[3], node_max_height - nodes[3].best_block_info().1); + // Construct the route parameters for sending to nodes[3]'s blinded path. let amt_msat = 100_000; let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[3], Some(amt_msat), None); @@ -381,10 +388,10 @@ fn bolt12_invoice_too_large_blinded_paths() { let payment_id = PaymentId([1; 32]); nodes[0].node.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), None).unwrap(); let invreq_om = nodes[0].onion_messenger.next_onion_message_for_peer(nodes[1].node.get_our_node_id()).unwrap(); - nodes[1].onion_messenger.handle_onion_message(&nodes[0].node.get_our_node_id(), &invreq_om); + nodes[1].onion_messenger.handle_onion_message(nodes[0].node.get_our_node_id(), &invreq_om); let invoice_om = nodes[1].onion_messenger.next_onion_message_for_peer(nodes[0].node.get_our_node_id()).unwrap(); - nodes[0].onion_messenger.handle_onion_message(&nodes[1].node.get_our_node_id(), &invoice_om); + nodes[0].onion_messenger.handle_onion_message(nodes[1].node.get_our_node_id(), &invoice_om); // TODO: assert on the invoice error once we support replying to invoice OMs with failure info nodes[0].logger.assert_log_contains("lightning::ln::channelmanager", "Failed paying invoice: OnionPacketSizeExceeded", 1); diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 200e5ed84f4..947ec4a1304 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -23,7 +23,6 @@ use crate::ln::msgs::ChannelMessageHandler; use crate::crypto::utils::sign; use crate::util::ser::Writeable; use crate::util::scid_utils::block_from_scid; -use crate::util::test_utils; use bitcoin::{Amount, PublicKey, ScriptBuf, Transaction, TxIn, TxOut, Witness}; use bitcoin::locktime::absolute::LockTime; @@ -71,7 +70,7 @@ fn chanmon_fail_from_stale_commitment() { let bs_txn = get_local_commitment_txn!(nodes[1], chan_id_2); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], updates.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -91,7 +90,7 @@ fn chanmon_fail_from_stale_commitment() { check_added_monitors!(nodes[1], 1); let fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], fail_updates.commitment_signed, true, true); expect_payment_failed_with_update!(nodes[0], payment_hash, false, update_a.contents.short_channel_id, true); } @@ -174,16 +173,16 @@ fn archive_fully_resolved_monitors() { nodes[0].node.close_channel(&chan_id, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, _) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); let shutdown_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); @@ -259,16 +258,16 @@ fn do_chanmon_claim_value_coop_close(anchors: bool) { nodes[0].node.close_channel(&chan_id, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); @@ -488,15 +487,15 @@ fn do_test_claim_value_force_close(anchors: bool, prev_commitment_tx: bool) { if prev_commitment_tx { // To build a previous commitment transaction, deliver one round of commitment messages. - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &b_htlc_msgs.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &b_htlc_msgs.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &b_htlc_msgs.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &b_htlc_msgs.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_raa, as_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_raa); let _htlc_updates = get_htlc_update_msgs!(&nodes[1], nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_cs); let _bs_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); } @@ -805,7 +804,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) { check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], updates.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -817,7 +816,7 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) { check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], updates.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1907,7 +1906,7 @@ fn do_test_revoked_counterparty_aggregated_claims(anchors: bool) { check_added_monitors!(nodes[0], 1); let fee_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap()); commitment_signed_dance!(nodes[1], nodes[0], fee_update.commitment_signed, false); nodes[0].node.claim_funds(claimed_payment_preimage); @@ -2251,6 +2250,10 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + // Reset our RNG counters to mirror the RNG output from when this test was written. + nodes[0].keys_manager.backing.inner.entropy_source.set_counter(0x1_0000_0004); + nodes[1].keys_manager.backing.inner.entropy_source.set_counter(0x1_0000_0004); + // Open a channel, lock in an HTLC, and immediately broadcast the commitment transaction. This // ensures that the HTLC timeout package is held until we reach its expiration height. let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 50_000_000); diff --git a/lightning/src/ln/msgs.rs b/lightning/src/ln/msgs.rs index c176a8669d3..c89274f47d8 100644 --- a/lightning/src/ln/msgs.rs +++ b/lightning/src/ln/msgs.rs @@ -87,7 +87,7 @@ pub enum DecodeError { ShortRead, /// A length descriptor in the packet didn't describe the later data correctly. BadLengthDescriptor, - /// Error from [`std::io`]. + /// Error from [`crate::io`]. Io(io::ErrorKind), /// The message included zlib-compressed values, which we don't support. UnsupportedCompression, @@ -1491,101 +1491,101 @@ pub struct CommitmentUpdate { 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); + 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); + 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); + 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); + 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); + fn handle_funding_created(&self, their_node_id: PublicKey, msg: &FundingCreated); /// Handle an incoming `funding_signed` message from the given peer. - fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &FundingSigned); + fn handle_funding_signed(&self, their_node_id: PublicKey, msg: &FundingSigned); /// Handle an incoming `channel_ready` message from the given peer. - fn handle_channel_ready(&self, their_node_id: &PublicKey, msg: &ChannelReady); + fn handle_channel_ready(&self, their_node_id: PublicKey, msg: &ChannelReady); // Channel close: /// Handle an incoming `shutdown` message from the given peer. - fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &Shutdown); + fn handle_shutdown(&self, their_node_id: PublicKey, msg: &Shutdown); /// Handle an incoming `closing_signed` message from the given peer. - fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned); + fn handle_closing_signed(&self, their_node_id: PublicKey, msg: &ClosingSigned); // Quiescence /// Handle an incoming `stfu` message from the given peer. - fn handle_stfu(&self, their_node_id: &PublicKey, msg: &Stfu); + fn handle_stfu(&self, their_node_id: PublicKey, msg: &Stfu); // Splicing /// Handle an incoming `splice_init` message from the given peer. #[cfg(splicing)] - fn handle_splice_init(&self, their_node_id: &PublicKey, msg: &SpliceInit); + fn handle_splice_init(&self, their_node_id: PublicKey, msg: &SpliceInit); /// Handle an incoming `splice_ack` message from the given peer. #[cfg(splicing)] - fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &SpliceAck); + fn handle_splice_ack(&self, their_node_id: PublicKey, msg: &SpliceAck); /// Handle an incoming `splice_locked` message from the given peer. #[cfg(splicing)] - fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &SpliceLocked); + fn handle_splice_locked(&self, their_node_id: PublicKey, msg: &SpliceLocked); // 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + fn handle_update_add_htlc(&self, their_node_id: PublicKey, msg: &UpdateAddHTLC); /// Handle an incoming `update_fulfill_htlc` message from the given peer. - fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFulfillHTLC); + fn handle_update_fulfill_htlc(&self, their_node_id: PublicKey, msg: &UpdateFulfillHTLC); /// Handle an incoming `update_fail_htlc` message from the given peer. - fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailHTLC); + fn handle_update_fail_htlc(&self, their_node_id: PublicKey, msg: &UpdateFailHTLC); /// Handle an incoming `update_fail_malformed_htlc` message from the given peer. - fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &UpdateFailMalformedHTLC); + fn handle_update_fail_malformed_htlc(&self, their_node_id: PublicKey, msg: &UpdateFailMalformedHTLC); /// Handle an incoming `commitment_signed` message from the given peer. - fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &CommitmentSigned); + fn handle_commitment_signed(&self, their_node_id: PublicKey, msg: &CommitmentSigned); /// Handle an incoming `revoke_and_ack` message from the given peer. - fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &RevokeAndACK); + fn handle_revoke_and_ack(&self, their_node_id: PublicKey, msg: &RevokeAndACK); /// Handle an incoming `update_fee` message from the given peer. - fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &UpdateFee); + fn handle_update_fee(&self, their_node_id: PublicKey, msg: &UpdateFee); // Channel-to-announce: /// Handle an incoming `announcement_signatures` message from the given peer. - fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &AnnouncementSignatures); + fn handle_announcement_signatures(&self, their_node_id: PublicKey, msg: &AnnouncementSignatures); // Connection loss/reestablish: /// Indicates a connection to the peer failed/an existing connection was lost. - fn peer_disconnected(&self, their_node_id: &PublicKey); + fn peer_disconnected(&self, their_node_id: PublicKey); /// Handle a peer reconnecting, possibly generating `channel_reestablish` message(s). /// /// May return an `Err(())` if the features the peer supports are not sufficient to communicate /// with us. Implementors should be somewhat conservative about doing so, however, as other /// message handlers may still wish to communicate with this peer. - fn peer_connected(&self, their_node_id: &PublicKey, msg: &Init, inbound: bool) -> Result<(), ()>; + fn peer_connected(&self, their_node_id: PublicKey, msg: &Init, inbound: bool) -> Result<(), ()>; /// Handle an incoming `channel_reestablish` message from the given peer. - fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &ChannelReestablish); + fn handle_channel_reestablish(&self, their_node_id: PublicKey, msg: &ChannelReestablish); /// Handle an incoming `channel_update` message from the given peer. - fn handle_channel_update(&self, their_node_id: &PublicKey, msg: &ChannelUpdate); + fn handle_channel_update(&self, their_node_id: PublicKey, msg: &ChannelUpdate); // Error: /// Handle an incoming `error` message from the given peer. - fn handle_error(&self, their_node_id: &PublicKey, msg: &ErrorMessage); + fn handle_error(&self, their_node_id: PublicKey, msg: &ErrorMessage); // Handler information: /// Gets the node feature flags which this handler itself supports. All available handlers are @@ -1598,13 +1598,21 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures; + fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures; /// Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. /// /// If it's `None`, then no particular network chain hash compatibility will be enforced when /// connecting to peers. fn get_chain_hashes(&self) -> Option>; + + /// Indicates that a message was received from any peer for any handler. + /// Called before the message is passed to the appropriate handler. + /// Useful for indicating that a network connection is active. + /// + /// Note: Since this function is called frequently, it should be as + /// efficient as possible for its intended purpose. + fn message_received(&self); } /// A trait to describe an object which can receive routing messages. @@ -1617,13 +1625,19 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider { pub trait RoutingMessageHandler : MessageSendEventsProvider { /// Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on, /// `false` or returning an `Err` otherwise. - fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result; + /// + /// If `their_node_id` is `None`, the message was generated by our own local node. + fn handle_node_announcement(&self, their_node_id: Option, msg: &NodeAnnouncement) -> Result; /// Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false` /// or returning an `Err` otherwise. - fn handle_channel_announcement(&self, msg: &ChannelAnnouncement) -> Result; + /// + /// If `their_node_id` is `None`, the message was generated by our own local node. + fn handle_channel_announcement(&self, their_node_id: Option, msg: &ChannelAnnouncement) -> Result; /// Handle an incoming `channel_update` message, returning true if it should be forwarded on, /// `false` or returning an `Err` otherwise. - fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result; + /// + /// If `their_node_id` is `None`, the message was generated by our own local node. + fn handle_channel_update(&self, their_node_id: Option, msg: &ChannelUpdate) -> Result; /// Gets channel announcements and updates required to dump our routing table to a remote node, /// starting at the `short_channel_id` indicated by `starting_point` and including announcements /// for a single channel. @@ -1640,22 +1654,22 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider { /// May return an `Err(())` if the features the peer supports are not sufficient to communicate /// with us. Implementors should be somewhat conservative about doing so, however, as other /// message handlers may still wish to communicate with this peer. - fn peer_connected(&self, their_node_id: &PublicKey, init: &Init, inbound: bool) -> Result<(), ()>; + fn peer_connected(&self, their_node_id: PublicKey, init: &Init, inbound: bool) -> Result<(), ()>; /// Handles the reply of a query we initiated to learn about channels /// for a given range of blocks. We can expect to receive one or more /// replies to a single query. - fn handle_reply_channel_range(&self, their_node_id: &PublicKey, msg: ReplyChannelRange) -> Result<(), LightningError>; + fn handle_reply_channel_range(&self, their_node_id: PublicKey, msg: ReplyChannelRange) -> Result<(), LightningError>; /// Handles the reply of a query we initiated asking for routing gossip /// messages for a list of channels. We should receive this message when /// a node has completed its best effort to send us the pertaining routing /// gossip messages. - fn handle_reply_short_channel_ids_end(&self, their_node_id: &PublicKey, msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError>; + fn handle_reply_short_channel_ids_end(&self, their_node_id: PublicKey, msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError>; /// Handles when a peer asks us to send a list of `short_channel_id`s /// for the requested range of blocks. - fn handle_query_channel_range(&self, their_node_id: &PublicKey, msg: QueryChannelRange) -> Result<(), LightningError>; + fn handle_query_channel_range(&self, their_node_id: PublicKey, msg: QueryChannelRange) -> Result<(), LightningError>; /// Handles when a peer asks us to send routing gossip messages for a /// list of `short_channel_id`s. - fn handle_query_short_channel_ids(&self, their_node_id: &PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>; + fn handle_query_short_channel_ids(&self, their_node_id: PublicKey, msg: QueryShortChannelIds) -> Result<(), LightningError>; // Handler queueing status: /// Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages @@ -1674,13 +1688,13 @@ pub trait RoutingMessageHandler : MessageSendEventsProvider { /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures; + fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures; } /// A handler for received [`OnionMessage`]s and for providing generated ones to send. pub trait OnionMessageHandler { /// Handle an incoming `onion_message` message from the given peer. - fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage); + fn handle_onion_message(&self, peer_node_id: PublicKey, msg: &OnionMessage); /// Returns the next pending onion message for the peer with the given node id. fn next_onion_message_for_peer(&self, peer_node_id: PublicKey) -> Option; @@ -1691,11 +1705,11 @@ pub trait OnionMessageHandler { /// May return an `Err(())` if the features the peer supports are not sufficient to communicate /// with us. Implementors should be somewhat conservative about doing so, however, as other /// message handlers may still wish to communicate with this peer. - fn peer_connected(&self, their_node_id: &PublicKey, init: &Init, inbound: bool) -> Result<(), ()>; + fn peer_connected(&self, their_node_id: PublicKey, init: &Init, inbound: bool) -> Result<(), ()>; /// Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to /// drop and refuse to forward onion messages to this peer. - fn peer_disconnected(&self, their_node_id: &PublicKey); + fn peer_disconnected(&self, their_node_id: PublicKey); /// Performs actions that should happen roughly every ten seconds after startup. Allows handlers /// to drop any buffered onion messages intended for prospective peers. @@ -1712,7 +1726,7 @@ pub trait OnionMessageHandler { /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures; + fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures; } #[derive(Clone)] diff --git a/lightning/src/ln/offers_tests.rs b/lightning/src/ln/offers_tests.rs index 8bbf9a0ad7d..7431285d2b9 100644 --- a/lightning/src/ln/offers_tests.rs +++ b/lightning/src/ln/offers_tests.rs @@ -47,7 +47,7 @@ use crate::blinded_path::IntroductionNode; use crate::blinded_path::message::BlindedMessagePath; use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext}; use crate::blinded_path::message::{MessageContext, OffersContext}; -use crate::events::{Event, MessageSendEventsProvider, PaymentFailureReason, PaymentPurpose}; +use crate::events::{ClosureReason, Event, MessageSendEventsProvider, PaymentFailureReason, PaymentPurpose}; use crate::ln::channelmanager::{Bolt12PaymentError, MAX_SHORT_LIVED_RELATIVE_EXPIRY, PaymentId, RecentPaymentDetails, Retry, self}; use crate::ln::features::Bolt12InvoiceFeatures; use crate::ln::functional_test_utils::*; @@ -59,11 +59,12 @@ use crate::offers::invoice_error::InvoiceError; use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields}; use crate::offers::nonce::Nonce; use crate::offers::parse::Bolt12SemanticError; -use crate::onion_message::messenger::{Destination, PeeledOnion, MessageSendInstructions}; +use crate::onion_message::messenger::{BlindedPathType, Destination, MessageSendInstructions, PeeledOnion}; use crate::onion_message::offers::OffersMessage; use crate::onion_message::packet::ParsedOnionMessageContents; use crate::routing::gossip::{NodeAlias, NodeId}; use crate::sign::{NodeSigner, Recipient}; +use crate::util::ser::Writeable; use crate::prelude::*; @@ -84,28 +85,28 @@ fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c let node_id_b = node_b.node.get_our_node_id(); let init_a = Init { - features: node_a.init_features(&node_id_b), + features: node_a.init_features(node_id_b), networks: None, remote_network_address: None, }; let init_b = Init { - features: node_b.init_features(&node_id_a), + features: node_b.init_features(node_id_a), networks: None, remote_network_address: None, }; - node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap(); - node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap(); - node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap(); - node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap(); + node_a.node.peer_connected(node_id_b, &init_b, true).unwrap(); + node_b.node.peer_connected(node_id_a, &init_a, false).unwrap(); + node_a.onion_messenger.peer_connected(node_id_b, &init_b, true).unwrap(); + node_b.onion_messenger.peer_connected(node_id_a, &init_a, false).unwrap(); } fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) { for node_b in peers { - node_a.node.peer_disconnected(&node_b.node.get_our_node_id()); - node_b.node.peer_disconnected(&node_a.node.get_our_node_id()); - node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id()); - node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id()); + node_a.node.peer_disconnected(node_b.node.get_our_node_id()); + node_b.node.peer_disconnected(node_a.node.get_our_node_id()); + node_a.onion_messenger.peer_disconnected(node_b.node.get_our_node_id()); + node_b.onion_messenger.peer_disconnected(node_a.node.get_our_node_id()); } } @@ -134,9 +135,10 @@ fn announce_node_address<'a, 'b, 'c>( contents: announcement }; - node.gossip_sync.handle_node_announcement(&msg).unwrap(); + let node_pubkey = node.node.get_our_node_id(); + node.gossip_sync.handle_node_announcement(None, &msg).unwrap(); for peer in peers { - peer.gossip_sync.handle_node_announcement(&msg).unwrap(); + peer.gossip_sync.handle_node_announcement(Some(node_pubkey), &msg).unwrap(); } } @@ -219,12 +221,12 @@ fn extract_invoice_request<'a, 'b, 'c>( } } -fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> (Bolt12Invoice, Option) { +fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> (Bolt12Invoice, BlindedMessagePath) { match node.onion_messenger.peel_onion_message(message) { Ok(PeeledOnion::Receive(message, _, reply_path)) => match message { ParsedOnionMessageContents::Offers(offers_message) => match offers_message { OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request), - OffersMessage::Invoice(invoice) => (invoice, reply_path), + OffersMessage::Invoice(invoice) => (invoice, reply_path.unwrap()), #[cfg(async_payments)] OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice), OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error), @@ -259,6 +261,53 @@ fn extract_invoice_error<'a, 'b, 'c>( } } +/// Checks that an offer can be created with no blinded paths. +#[test] +fn create_offer_with_no_blinded_path() { + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000); + + let alice = &nodes[0]; + let alice_id = alice.node.get_our_node_id(); + + let offer = alice.node + .create_offer_builder(None).unwrap() + .amount_msats(10_000_000) + .build().unwrap(); + assert_eq!(offer.issuer_signing_pubkey(), Some(alice_id)); + assert!(offer.paths().is_empty()); +} + +/// Checks that a refund can be created with no blinded paths. +#[test] +fn create_refund_with_no_blinded_path() { + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000); + + let alice = &nodes[0]; + let alice_id = alice.node.get_our_node_id(); + + let absolute_expiry = Duration::from_secs(u64::MAX); + let payment_id = PaymentId([1; 32]); + + let refund = alice.node + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, None) + .unwrap() + .build().unwrap(); + assert_eq!(refund.amount_msats(), 10_000_000); + assert_eq!(refund.absolute_expiry(), Some(absolute_expiry)); + assert_eq!(refund.payer_signing_pubkey(), alice_id); + assert!(refund.paths().is_empty()); +} + /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer. #[test] fn prefers_non_tor_nodes_in_blinded_paths() { @@ -301,10 +350,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() { announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone()); let offer = bob.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(bob_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { let introduction_node_id = resolve_introduction_node(david, &path); @@ -317,10 +366,10 @@ fn prefers_non_tor_nodes_in_blinded_paths() { announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone()); let offer = bob.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(bob_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { let introduction_node_id = resolve_introduction_node(david, &path); @@ -368,10 +417,10 @@ fn prefers_more_connected_nodes_in_blinded_paths() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = bob.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(bob_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(bob_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { let introduction_node_id = resolve_introduction_node(david, &path); @@ -395,7 +444,8 @@ fn creates_short_lived_offer() { let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY; let offer = alice.node - .create_offer_builder(Some(absolute_expiry)).unwrap() + .create_offer_builder(Some(BlindedPathType::Compact)).unwrap() + .absolute_expiry(absolute_expiry) .build().unwrap(); assert_eq!(offer.absolute_expiry(), Some(absolute_expiry)); assert!(!offer.paths().is_empty()); @@ -422,8 +472,8 @@ fn creates_long_lived_offer() { let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY + Duration::from_secs(1); let offer = alice.node - .create_offer_builder(Some(absolute_expiry)) - .unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() + .absolute_expiry(absolute_expiry) .build().unwrap(); assert_eq!(offer.absolute_expiry(), Some(absolute_expiry)); assert!(!offer.paths().is_empty()); @@ -432,7 +482,7 @@ fn creates_long_lived_offer() { } let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .build().unwrap(); assert_eq!(offer.absolute_expiry(), None); assert!(!offer.paths().is_empty()); @@ -458,7 +508,7 @@ fn creates_short_lived_refund() { let absolute_expiry = bob.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY; let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Compact)) .unwrap() .build().unwrap(); assert_eq!(refund.absolute_expiry(), Some(absolute_expiry)); @@ -487,7 +537,7 @@ fn creates_long_lived_refund() { + Duration::from_secs(1); let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); assert_eq!(refund.absolute_expiry(), Some(absolute_expiry)); @@ -536,11 +586,11 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None) + .create_offer_builder(Some(BlindedPathType::Full)) .unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); @@ -554,39 +604,48 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: offer.id(), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: None, payer_note_truncated: None, }, }); assert_eq!(invoice_request.amount_msats(), None); - assert_ne!(invoice_request.payer_id(), david_id); + assert_ne!(invoice_request.payer_signing_pubkey(), david_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); - let (invoice, _) = extract_invoice(david, &onion_message); + let (invoice, reply_path) = extract_invoice(david, &onion_message); assert_eq!(invoice.amount_msats(), 10_000_000); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); for path in invoice.payment_paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); } + // Both Bob and Charlie have an equal number of channels and need to be connected + // to Alice when she's handling the message. Therefore, either Bob or Charlie could + // serve as the introduction node for the reply path back to Alice. + assert!( + matches!( + reply_path.introduction_node(), + &IntroductionNode::NodeId(node_id) if node_id == bob_id || node_id == charlie_id, + ) + ); route_bolt12_payment(david, &[charlie, bob, alice], &invoice); expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id); @@ -636,12 +695,12 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); assert_eq!(refund.amount_msats(), 10_000_000); assert_eq!(refund.absolute_expiry(), Some(absolute_expiry)); - assert_ne!(refund.payer_id(), david_id); + assert_ne!(refund.payer_signing_pubkey(), david_id); assert!(!refund.paths().is_empty()); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); @@ -654,12 +713,12 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() { connect_peers(alice, charlie); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); - let (invoice, _) = extract_invoice(david, &onion_message); + let (invoice, reply_path) = extract_invoice(david, &onion_message); assert_eq!(invoice, expected_invoice); assert_eq!(invoice.amount_msats(), 10_000_000); @@ -668,6 +727,8 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() { for path in invoice.payment_paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); } + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id)); + route_bolt12_payment(david, &[charlie, bob, alice], &invoice); expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id); @@ -694,10 +755,10 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); @@ -708,31 +769,32 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() { expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: offer.id(), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: None, payer_note_truncated: None, }, }); assert_eq!(invoice_request.amount_msats(), None); - assert_ne!(invoice_request.payer_id(), bob_id); + assert_ne!(invoice_request.payer_signing_pubkey(), bob_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id)); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); - let (invoice, _) = extract_invoice(bob, &onion_message); + let (invoice, reply_path) = extract_invoice(bob, &onion_message); assert_eq!(invoice.amount_msats(), 10_000_000); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); for path in invoice.payment_paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); } + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(alice_id)); route_bolt12_payment(bob, &[alice], &invoice); expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id); @@ -761,12 +823,12 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); assert_eq!(refund.amount_msats(), 10_000_000); assert_eq!(refund.absolute_expiry(), Some(absolute_expiry)); - assert_ne!(refund.payer_id(), bob_id); + assert_ne!(refund.payer_signing_pubkey(), bob_id); assert!(!refund.paths().is_empty()); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); @@ -777,9 +839,9 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() { let expected_invoice = alice.node.request_refund_payment(&refund).unwrap(); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); - let (invoice, _) = extract_invoice(bob, &onion_message); + let (invoice, reply_path) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); assert_eq!(invoice.amount_msats(), 10_000_000); @@ -788,6 +850,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() { for path in invoice.payment_paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); } + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(alice_id)); route_bolt12_payment(bob, &[alice], &invoice); expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id); @@ -814,11 +877,11 @@ fn pays_for_offer_without_blinded_paths() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .clear_paths() .amount_msats(10_000_000) .build().unwrap(); - assert_eq!(offer.signing_pubkey(), Some(alice_id)); + assert_eq!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(offer.paths().is_empty()); let payment_id = PaymentId([1; 32]); @@ -826,20 +889,20 @@ fn pays_for_offer_without_blinded_paths() { expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, _) = extract_invoice_request(alice, &onion_message); let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: offer.id(), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: None, payer_note_truncated: None, }, }); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); let (invoice, _) = extract_invoice(bob, &onion_message); route_bolt12_payment(bob, &[alice], &invoice); @@ -868,11 +931,11 @@ fn pays_for_refund_without_blinded_paths() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .clear_paths() .build().unwrap(); - assert_eq!(refund.payer_id(), bob_id); + assert_eq!(refund.payer_signing_pubkey(), bob_id); assert!(refund.paths().is_empty()); expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); @@ -880,7 +943,7 @@ fn pays_for_refund_without_blinded_paths() { let expected_invoice = alice.node.request_refund_payment(&refund).unwrap(); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); let (invoice, _) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); @@ -937,11 +1000,11 @@ fn send_invoice_requests_with_distinct_reply_path() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None) + .create_offer_builder(Some(BlindedPathType::Full)) .unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); @@ -955,22 +1018,22 @@ fn send_invoice_requests_with_distinct_reply_path() { // Send, extract and verify the first Invoice Request message let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (_, reply_path) = extract_invoice_request(alice, &onion_message); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); // Send, extract and verify the second Invoice Request message let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (_, reply_path) = extract_invoice_request(alice, &onion_message); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(nodes[6].node.get_our_node_id())); @@ -1023,10 +1086,10 @@ fn send_invoice_for_refund_with_distinct_reply_path() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = alice.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); - assert_ne!(refund.payer_id(), alice_id); + assert_ne!(refund.payer_signing_pubkey(), alice_id); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); } @@ -1037,23 +1100,95 @@ fn send_invoice_for_refund_with_distinct_reply_path() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); let (_, reply_path) = extract_invoice(alice, &onion_message); - assert_eq!(reply_path.unwrap().introduction_node(), &IntroductionNode::NodeId(charlie_id)); + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); // Send, extract and verify the second Invoice Request message let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); let (_, reply_path) = extract_invoice(alice, &onion_message); - assert_eq!(reply_path.unwrap().introduction_node(), &IntroductionNode::NodeId(nodes[6].node.get_our_node_id())); + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(nodes[6].node.get_our_node_id())); +} + +/// Verifies that the invoice request message can be retried if it fails to reach the +/// payee on the first attempt. +#[test] +fn creates_and_pays_for_offer_with_retry() { + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); + + create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000); + + let alice = &nodes[0]; + let alice_id = alice.node.get_our_node_id(); + let bob = &nodes[1]; + let bob_id = bob.node.get_our_node_id(); + + let offer = alice.node + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() + .amount_msats(10_000_000) + .build().unwrap(); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); + assert!(!offer.paths().is_empty()); + for path in offer.paths() { + assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); + } + let payment_id = PaymentId([1; 32]); + bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap(); + expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); + + let _lost_onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); + + // Simulate a scenario where the original onion_message is lost before reaching Alice. + // Use handle_message_received to regenerate the message. + bob.node.message_received(); + let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); + + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); + + let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); + let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { + offer_id: offer.id(), + invoice_request: InvoiceRequestFields { + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), + quantity: None, + payer_note_truncated: None, + }, + }); + assert_eq!(invoice_request.amount_msats(), None); + assert_ne!(invoice_request.payer_signing_pubkey(), bob_id); + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id)); + let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); + + // Expect no more OffersMessage to be enqueued by this point, even after calling + // handle_message_received. + bob.node.message_received(); + + assert!(bob.onion_messenger.next_onion_message_for_peer(alice_id).is_none()); + + let (invoice, _) = extract_invoice(bob, &onion_message); + assert_eq!(invoice.amount_msats(), 10_000_000); + assert_ne!(invoice.signing_pubkey(), alice_id); + assert!(!invoice.payment_paths().is_empty()); + for path in invoice.payment_paths() { + assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); + } + route_bolt12_payment(bob, &[alice], &invoice); + expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id); + claim_bolt12_payment(bob, &[alice], payment_context); + expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id); } /// Checks that a deferred invoice can be paid asynchronously from an Event::InvoiceReceived. @@ -1075,7 +1210,7 @@ fn pays_bolt12_invoice_asynchronously() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -1084,20 +1219,20 @@ fn pays_bolt12_invoice_asynchronously() { expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, _) = extract_invoice_request(alice, &onion_message); let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: offer.id(), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: None, payer_note_truncated: None, }, }); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); let (invoice, context) = match get_event!(bob, Event::InvoiceReceived) { Event::InvoiceReceived { payment_id: actual_payment_id, invoice, context, .. } => { @@ -1159,10 +1294,10 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() { let bob_id = bob.node.get_our_node_id(); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); @@ -1173,29 +1308,30 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() { expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext { offer_id: offer.id(), invoice_request: InvoiceRequestFields { - payer_id: invoice_request.payer_id(), + payer_signing_pubkey: invoice_request.payer_signing_pubkey(), quantity: None, payer_note_truncated: None, }, }); - assert_ne!(invoice_request.payer_id(), bob_id); + assert_ne!(invoice_request.payer_signing_pubkey(), bob_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(alice_id)); let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&alice_id, &onion_message); + bob.onion_messenger.handle_onion_message(alice_id, &onion_message); - let (invoice, _) = extract_invoice(bob, &onion_message); + let (invoice, reply_path) = extract_invoice(bob, &onion_message); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); for path in invoice.payment_paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); } + assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id)); route_bolt12_payment(bob, &[alice], &invoice); expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id); @@ -1225,10 +1361,10 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); - assert_ne!(refund.payer_id(), bob_id); + assert_ne!(refund.payer_signing_pubkey(), bob_id); assert!(!refund.paths().is_empty()); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id)); @@ -1239,7 +1375,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() { let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - let (invoice, _) = extract_invoice(bob, &onion_message); + let (invoice, _reply_path) = extract_invoice(bob, &onion_message); assert_eq!(invoice, expected_invoice); assert_ne!(invoice.signing_pubkey(), alice_id); assert!(!invoice.payment_paths().is_empty()); @@ -1287,19 +1423,19 @@ fn fails_authentication_when_handling_invoice_request() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None) + .create_offer_builder(Some(BlindedPathType::Full)) .unwrap() .amount_msats(10_000_000) .build().unwrap(); assert_eq!(offer.metadata(), None); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); } let invalid_path = alice.node - .create_offer_builder(None) + .create_offer_builder(Some(BlindedPathType::Full)) .unwrap() .build().unwrap() .paths().first().unwrap() @@ -1320,11 +1456,11 @@ fn fails_authentication_when_handling_invoice_request() { } let onion_message = david.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&david_id, &onion_message); + alice.onion_messenger.handle_onion_message(david_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); assert_eq!(invoice_request.amount_msats(), None); - assert_ne!(invoice_request.payer_id(), david_id); + assert_ne!(invoice_request.payer_signing_pubkey(), david_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None); @@ -1347,14 +1483,14 @@ fn fails_authentication_when_handling_invoice_request() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); assert_eq!(invoice_request.amount_msats(), None); - assert_ne!(invoice_request.payer_id(), david_id); + assert_ne!(invoice_request.payer_signing_pubkey(), david_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); assert_eq!(alice.onion_messenger.next_onion_message_for_peer(charlie_id), None); @@ -1399,11 +1535,11 @@ fn fails_authentication_when_handling_invoice_for_offer() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None) + .create_offer_builder(Some(BlindedPathType::Full)) .unwrap() .amount_msats(10_000_000) .build().unwrap(); - assert_ne!(offer.signing_pubkey(), Some(alice_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(alice_id)); assert!(!offer.paths().is_empty()); for path in offer.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id)); @@ -1447,23 +1583,23 @@ fn fails_authentication_when_handling_invoice_for_offer() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); assert_eq!(invoice_request.amount_msats(), None); - assert_ne!(invoice_request.payer_id(), david_id); + assert_ne!(invoice_request.payer_signing_pubkey(), david_id); assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id); } @@ -1508,10 +1644,10 @@ fn fails_authentication_when_handling_invoice_for_refund() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); - assert_ne!(refund.payer_id(), david_id); + assert_ne!(refund.payer_signing_pubkey(), david_id); assert!(!refund.paths().is_empty()); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); @@ -1529,7 +1665,7 @@ fn fails_authentication_when_handling_invoice_for_refund() { } let onion_message = alice.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&alice_id, &onion_message); + david.onion_messenger.handle_onion_message(alice_id, &onion_message); let (invoice, _) = extract_invoice(david, &onion_message); assert_eq!(invoice, expected_invoice); @@ -1542,10 +1678,10 @@ fn fails_authentication_when_handling_invoice_for_refund() { let invalid_path = refund.paths().first().unwrap().clone(); let payment_id = PaymentId([2; 32]); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); - assert_ne!(refund.payer_id(), david_id); + assert_ne!(refund.payer_signing_pubkey(), david_id); assert!(!refund.paths().is_empty()); for path in refund.paths() { assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(charlie_id)); @@ -1562,10 +1698,10 @@ fn fails_authentication_when_handling_invoice_for_refund() { connect_peers(alice, charlie); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); let (invoice, _) = extract_invoice(david, &onion_message); assert_eq!(invoice, expected_invoice); @@ -1596,7 +1732,7 @@ fn fails_creating_or_paying_for_offer_without_connected_peers() { disconnect_peers(david, &[bob, charlie, &nodes[4], &nodes[5]]); let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY; - match alice.node.create_offer_builder(Some(absolute_expiry)) { + match alice.node.create_offer_builder(Some(BlindedPathType::Full)) { Ok(_) => panic!("Expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths), } @@ -1606,7 +1742,8 @@ fn fails_creating_or_paying_for_offer_without_connected_peers() { reconnect_nodes(args); let offer = alice.node - .create_offer_builder(Some(absolute_expiry)).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() + .absolute_expiry(absolute_expiry) .amount_msats(10_000_000) .build().unwrap(); @@ -1669,7 +1806,7 @@ fn fails_creating_refund_or_sending_invoice_without_connected_peers() { let absolute_expiry = david.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY; let payment_id = PaymentId([1; 32]); match david.node.create_refund_builder( - 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None + 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full) ) { Ok(_) => panic!("Expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths), @@ -1680,7 +1817,7 @@ fn fails_creating_refund_or_sending_invoice_without_connected_peers() { reconnect_nodes(args); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); @@ -1710,7 +1847,7 @@ fn fails_creating_invoice_request_for_unsupported_chain() { let bob = &nodes[1]; let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .clear_chains() .chain(Network::Signet) .build().unwrap(); @@ -1738,7 +1875,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = bob.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .chain(Network::Signet) .build().unwrap(); @@ -1769,7 +1906,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() { disconnect_peers(david, &[bob, charlie, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -1803,7 +1940,7 @@ fn fails_creating_invoice_request_with_duplicate_payment_id() { disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -1836,13 +1973,13 @@ fn fails_creating_refund_with_duplicate_payment_id() { let payment_id = PaymentId([1; 32]); assert!( nodes[0].node.create_refund_builder( - 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None + 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full) ).is_ok() ); expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id); match nodes[0].node.create_refund_builder( - 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None + 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full) ) { Ok(_) => panic!("Expected error"), Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId), @@ -1889,7 +2026,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -1900,18 +2037,18 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_offer() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); let invoice_error = extract_invoice_error(david, &onion_message); assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths)); @@ -1962,7 +2099,7 @@ fn fails_sending_invoice_without_blinded_payment_paths_for_refund() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); @@ -2011,7 +2148,7 @@ fn fails_paying_invoice_more_than_once() { let absolute_expiry = Duration::from_secs(u64::MAX); let payment_id = PaymentId([1; 32]); let refund = david.node - .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None) + .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None, Some(BlindedPathType::Full)) .unwrap() .build().unwrap(); expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id); @@ -2022,10 +2159,10 @@ fn fails_paying_invoice_more_than_once() { connect_peers(alice, charlie); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); // David initiates paying the first invoice let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {}); @@ -2043,10 +2180,10 @@ fn fails_paying_invoice_more_than_once() { connect_peers(david, bob); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); let (invoice2, _) = extract_invoice(david, &onion_message); assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata()); @@ -2098,7 +2235,7 @@ fn fails_paying_invoice_with_unknown_required_features() { disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]); let offer = alice.node - .create_offer_builder(None).unwrap() + .create_offer_builder(Some(BlindedPathType::Full)).unwrap() .amount_msats(10_000_000) .build().unwrap(); @@ -2109,18 +2246,18 @@ fn fails_paying_invoice_with_unknown_required_features() { connect_peers(david, bob); let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); - bob.onion_messenger.handle_onion_message(&david_id, &onion_message); + bob.onion_messenger.handle_onion_message(david_id, &onion_message); connect_peers(alice, charlie); let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); - alice.onion_messenger.handle_onion_message(&bob_id, &onion_message); + alice.onion_messenger.handle_onion_message(bob_id, &onion_message); let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message); let nonce = extract_offer_nonce(alice, &onion_message); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); // Drop the invoice in favor for one with unknown required features. let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); @@ -2147,10 +2284,10 @@ fn fails_paying_invoice_with_unknown_required_features() { alice.node.pending_offers_messages.lock().unwrap().push((message, instructions)); let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap(); - charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message); + charlie.onion_messenger.handle_onion_message(alice_id, &onion_message); let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap(); - david.onion_messenger.handle_onion_message(&charlie_id, &onion_message); + david.onion_messenger.handle_onion_message(charlie_id, &onion_message); // Confirm that david drops this failed payment from his pending outbound payments. match get_event!(david, Event::PaymentFailed) { @@ -2166,3 +2303,92 @@ fn fails_paying_invoice_with_unknown_required_features() { _ => panic!("Expected Event::PaymentFailed with reason"), } } + +#[test] +fn no_double_pay_with_stale_channelmanager() { + // This tests the following bug: + // - An outbound payment is AwaitingInvoice + // - We receive an invoice and lock the HTLCs into the relevant ChannelMonitors + // - The monitors are successfully persisted, but the ChannelManager fails to persist, so the + // payment remains AwaitingInvoice + // - We restart, causing the channels to close due to a stale ChannelManager + // - We receive a duplicate invoice, and attempt to pay it again due to the payment still being + // AwaitingInvoice in the stale ChannelManager + // After the fix for this, we will notice that the payment is already locked into the monitors on + // startup and transition the incorrectly-AwaitingInvoice payment to Retryable, which prevents + // double-paying on duplicate invoice receipt. + let chanmon_cfgs = create_chanmon_cfgs(2); + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); + let persister; + let chain_monitor; + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); + let alice_deserialized; + let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + let chan_id_0 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000).2; + let chan_id_1 = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000).2; + + let alice_id = nodes[0].node.get_our_node_id(); + let bob_id = nodes[1].node.get_our_node_id(); + + let amt_msat = nodes[0].node.list_usable_channels()[0].next_outbound_htlc_limit_msat + 1; // Force MPP + let offer = nodes[1].node + .create_offer_builder(None).unwrap() + .clear_paths() + .amount_msats(amt_msat) + .build().unwrap(); + assert_eq!(offer.issuer_signing_pubkey(), Some(bob_id)); + assert!(offer.paths().is_empty()); + + let payment_id = PaymentId([1; 32]); + nodes[0].node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap(); + expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id); + + let invreq_om = nodes[0].onion_messenger.next_onion_message_for_peer(bob_id).unwrap(); + nodes[1].onion_messenger.handle_onion_message(alice_id, &invreq_om); + + // Save the manager while the payment is in state AwaitingInvoice so we can reload it later. + let alice_chan_manager_serialized = nodes[0].node.encode(); + + let invoice_om = nodes[1].onion_messenger.next_onion_message_for_peer(alice_id).unwrap(); + nodes[0].onion_messenger.handle_onion_message(bob_id, &invoice_om); + let payment_hash = extract_invoice(&nodes[0], &invoice_om).0.payment_hash(); + + let expected_route: &[&[&Node]] = &[&[&nodes[1]], &[&nodes[1]]]; + let mut events = nodes[0].node.get_and_clear_pending_msg_events(); + assert_eq!(events.len(), 2); + check_added_monitors!(nodes[0], 2); + + let ev = remove_first_msg_event_to_node(&bob_id, &mut events); + let args = PassAlongPathArgs::new(&nodes[0], expected_route[0], amt_msat, payment_hash, ev) + .without_clearing_recipient_events(); + do_pass_along_path(args); + + let ev = remove_first_msg_event_to_node(&bob_id, &mut events); + let args = PassAlongPathArgs::new(&nodes[0], expected_route[0], amt_msat, payment_hash, ev) + .without_clearing_recipient_events(); + do_pass_along_path(args); + + expect_recent_payment!(nodes[0], RecentPaymentDetails::Pending, payment_id); + match get_event!(nodes[1], Event::PaymentClaimable) { + Event::PaymentClaimable { .. } => {}, + _ => panic!("No Event::PaymentClaimable"), + } + + // Reload with the stale manager and check that receiving the invoice again won't result in a + // duplicate payment attempt. + let monitor_0 = get_monitor!(nodes[0], chan_id_0).encode(); + let monitor_1 = get_monitor!(nodes[0], chan_id_1).encode(); + reload_node!(nodes[0], &alice_chan_manager_serialized, &[&monitor_0, &monitor_1], persister, chain_monitor, alice_deserialized); + // The stale manager results in closing the channels. + check_closed_event!(nodes[0], 2, ClosureReason::OutdatedChannelManager, [bob_id, bob_id], 10_000_000); + check_added_monitors!(nodes[0], 2); + + // Alice receives a duplicate invoice, but the payment should be transitioned to Retryable by now. + nodes[0].onion_messenger.handle_onion_message(bob_id, &invoice_om); + // Previously, Alice would've attempted to pay the invoice a 2nd time. In this test case, this 2nd + // attempt would have resulted in a PaymentFailed event here, since the only channels between + // Alice and Bob is closed. Since no 2nd attempt should be made, check that no events are + // generated in response to the duplicate invoice. + assert!(nodes[0].node.get_and_clear_pending_events().is_empty()); +} + diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 0ddadd21614..081cca2efae 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -99,7 +99,7 @@ fn run_onion_failure_test_with_fail_intercept( callback_node(); } // 0 => 1 update_add & CS - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_0); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_0); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); let update_1_0 = match test_case { @@ -126,7 +126,7 @@ fn run_onion_failure_test_with_fail_intercept( } // 1 => 2 - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_1); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add_1); commitment_signed_dance!(nodes[2], nodes[1], update_1.commitment_signed, false, true); if test_case == 2 || test_case == 200 { @@ -148,7 +148,7 @@ fn run_onion_failure_test_with_fail_intercept( } // 2 => 1 - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &fail_msg); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[1], nodes[2], update_2_1.commitment_signed, true); // backward fail on 1 @@ -165,9 +165,9 @@ fn run_onion_failure_test_with_fail_intercept( if test_case == 100 { callback_fail(&mut fail_msg); } - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); } else { - nodes[0].node.handle_update_fail_malformed_htlc(&nodes[1].node.get_our_node_id(), &update_1_0.update_fail_malformed_htlcs[0]); + nodes[0].node.handle_update_fail_malformed_htlc(nodes[1].node.get_our_node_id(), &update_1_0.update_fail_malformed_htlcs[0]); }; commitment_signed_dance!(nodes[0], nodes[1], update_1_0.commitment_signed, false, true); @@ -601,8 +601,8 @@ fn test_onion_failure() { let short_channel_id = channels[1].0.contents.short_channel_id; run_onion_failure_test("channel_disabled", 0, &nodes, &route, &payment_hash, &payment_secret, |_| {}, || { // disconnect event to the channel between nodes[1] ~ nodes[2] - nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); }, true, Some(UPDATE|7), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: false }), Some(short_channel_id)); @@ -728,7 +728,7 @@ fn test_overshoot_final_cltv() { check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add_0 = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_0); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_0); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -746,7 +746,7 @@ fn test_overshoot_final_cltv() { check_added_monitors!(&nodes[1], 1); let update_1 = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); let mut update_add_1 = update_1.update_add_htlcs[0].clone(); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_1); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add_1); commitment_signed_dance!(nodes[2], nodes[1], update_1.commitment_signed, false, true); expect_pending_htlcs_forwardable!(nodes[2]); @@ -1018,7 +1018,7 @@ fn do_test_fail_htlc_backwards_with_reason(failure_code: FailureCode) { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1042,7 +1042,7 @@ fn do_test_fail_htlc_backwards_with_reason(failure_code: FailureCode) { _ => panic!("Unexpected event"), }; - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlc); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlc); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false, true); let failure_data = match failure_code { @@ -1139,7 +1139,7 @@ fn test_phantom_onion_hmac_failure() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); // Modify the payload so the phantom hop's HMAC is bogus. @@ -1167,7 +1167,7 @@ fn test_phantom_onion_hmac_failure() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1201,7 +1201,7 @@ fn test_phantom_invalid_onion_payload() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); // Modify the onion packet to have an invalid payment amount. @@ -1243,7 +1243,7 @@ fn test_phantom_invalid_onion_payload() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1276,7 +1276,7 @@ fn test_phantom_final_incorrect_cltv_expiry() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); // Modify the payload so the phantom hop's HMAC is bogus. @@ -1300,7 +1300,7 @@ fn test_phantom_final_incorrect_cltv_expiry() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1336,7 +1336,7 @@ fn test_phantom_failure_too_low_cltv() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); expect_pending_htlcs_forwardable_ignore!(nodes[1]); @@ -1347,7 +1347,7 @@ fn test_phantom_failure_too_low_cltv() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1387,13 +1387,13 @@ fn test_phantom_failure_modified_cltv() { // Modify the route to have a too-low cltv. update_add.cltv_expiry -= 10; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); let update_1 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1427,13 +1427,13 @@ fn test_phantom_failure_expires_too_soon() { let mut update_add = update_0.update_add_htlcs[0].clone(); connect_blocks(&nodes[1], CLTV_FAR_FAR_AWAY); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); let update_1 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1465,7 +1465,7 @@ fn test_phantom_failure_too_low_recv_amt() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); expect_pending_htlcs_forwardable_ignore!(nodes[1]); @@ -1478,7 +1478,7 @@ fn test_phantom_failure_too_low_recv_amt() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1525,13 +1525,13 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); let update_1 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1569,7 +1569,7 @@ fn test_phantom_failure_reject_payment() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); expect_pending_htlcs_forwardable_ignore!(nodes[1]); @@ -1585,7 +1585,7 @@ fn test_phantom_failure_reject_payment() { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the payment fails with the expected error. diff --git a/lightning/src/ln/outbound_payment.rs b/lightning/src/ln/outbound_payment.rs index 69e97aa3573..2bc1c9b4edc 100644 --- a/lightning/src/ln/outbound_payment.rs +++ b/lightning/src/ln/outbound_payment.rs @@ -22,6 +22,8 @@ use crate::ln::features::Bolt12InvoiceFeatures; use crate::ln::onion_utils; use crate::ln::onion_utils::{DecodedOnionFailure, HTLCFailReason}; use crate::offers::invoice::Bolt12Invoice; +use crate::offers::invoice_request::InvoiceRequest; +use crate::offers::nonce::Nonce; use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, PaymentParameters, Route, RouteParameters, Router}; use crate::sign::{EntropySource, NodeSigner, Recipient}; use crate::util::errors::APIError; @@ -30,8 +32,15 @@ use crate::util::logger::Logger; use crate::util::time::Instant; use crate::util::ser::ReadableArgs; +#[cfg(async_payments)] +use { + crate::offers::invoice::{DerivedSigningPubkey, InvoiceBuilder}, + crate::offers::static_invoice::StaticInvoice, +}; + use core::fmt::{self, Display, Formatter}; use core::ops::Deref; +use core::sync::atomic::{AtomicBool, Ordering}; use core::time::Duration; use crate::prelude::*; @@ -53,7 +62,11 @@ pub(crate) enum PendingOutboundPayment { expiration: StaleExpiration, retry_strategy: Retry, max_total_routing_fee_msat: Option, + retryable_invoice_request: Option }, + // This state will never be persisted to disk because we transition from `AwaitingInvoice` to + // `Retryable` atomically within the `ChannelManager::total_consistency_lock`. Useful to avoid + // holding the `OutboundPayments::pending_outbound_payments` lock during pathfinding. InvoiceReceived { payment_hash: PaymentHash, retry_strategy: Retry, @@ -61,6 +74,16 @@ pub(crate) enum PendingOutboundPayment { // used anywhere. max_total_routing_fee_msat: Option, }, + // This state applies when we are paying an often-offline recipient and another node on the + // network served us a static invoice on the recipient's behalf in response to our invoice + // request. As a result, once a payment gets in this state it will remain here until the recipient + // comes back online, which may take hours or even days. + StaticInvoiceReceived { + payment_hash: PaymentHash, + keysend_preimage: PaymentPreimage, + retry_strategy: Retry, + route_params: RouteParameters, + }, Retryable { retry_strategy: Option, attempts: PaymentAttempts, @@ -100,6 +123,16 @@ pub(crate) enum PendingOutboundPayment { }, } +pub(crate) struct RetryableInvoiceRequest { + pub(crate) invoice_request: InvoiceRequest, + pub(crate) nonce: Nonce, +} + +impl_writeable_tlv_based!(RetryableInvoiceRequest, { + (0, invoice_request, required), + (2, nonce, required), +}); + impl PendingOutboundPayment { fn increment_attempts(&mut self) { if let PendingOutboundPayment::Retryable { attempts, .. } = self { @@ -168,6 +201,7 @@ impl PendingOutboundPayment { PendingOutboundPayment::Legacy { .. } => None, PendingOutboundPayment::AwaitingInvoice { .. } => None, PendingOutboundPayment::InvoiceReceived { payment_hash, .. } => Some(*payment_hash), + PendingOutboundPayment::StaticInvoiceReceived { payment_hash, .. } => Some(*payment_hash), PendingOutboundPayment::Retryable { payment_hash, .. } => Some(*payment_hash), PendingOutboundPayment::Fulfilled { payment_hash, .. } => *payment_hash, PendingOutboundPayment::Abandoned { payment_hash, .. } => Some(*payment_hash), @@ -182,27 +216,34 @@ impl PendingOutboundPayment { PendingOutboundPayment::Fulfilled { session_privs, .. } | PendingOutboundPayment::Abandoned { session_privs, .. } => session_privs, PendingOutboundPayment::AwaitingInvoice { .. } | - PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); return; }, + PendingOutboundPayment::InvoiceReceived { .. } | + PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); return; }, }); let payment_hash = self.payment_hash(); *self = PendingOutboundPayment::Fulfilled { session_privs, payment_hash, timer_ticks_without_htlcs: 0 }; } fn mark_abandoned(&mut self, reason: PaymentFailureReason) { - if let PendingOutboundPayment::Retryable { session_privs, payment_hash, .. } = self { - let mut our_session_privs = new_hash_set(); - core::mem::swap(&mut our_session_privs, session_privs); - *self = PendingOutboundPayment::Abandoned { - session_privs: our_session_privs, - payment_hash: *payment_hash, - reason: Some(reason) - }; - } else if let PendingOutboundPayment::InvoiceReceived { payment_hash, .. } = self { - *self = PendingOutboundPayment::Abandoned { - session_privs: new_hash_set(), - payment_hash: *payment_hash, - reason: Some(reason) - }; + let session_privs = match self { + PendingOutboundPayment::Retryable { session_privs, .. } => { + let mut our_session_privs = new_hash_set(); + core::mem::swap(&mut our_session_privs, session_privs); + our_session_privs + }, + _ => new_hash_set(), + }; + match self { + Self::Retryable { payment_hash, .. } | + Self::InvoiceReceived { payment_hash, .. } | + Self::StaticInvoiceReceived { payment_hash, .. } => + { + *self = Self::Abandoned { + session_privs, + payment_hash: *payment_hash, + reason: Some(reason), + }; + }, + _ => {} } } @@ -216,7 +257,8 @@ impl PendingOutboundPayment { session_privs.remove(session_priv) }, PendingOutboundPayment::AwaitingInvoice { .. } | - PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false }, + PendingOutboundPayment::InvoiceReceived { .. } | + PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); false }, }; if remove_res { if let PendingOutboundPayment::Retryable { @@ -245,7 +287,8 @@ impl PendingOutboundPayment { session_privs.insert(session_priv) }, PendingOutboundPayment::AwaitingInvoice { .. } | - PendingOutboundPayment::InvoiceReceived { .. } => { debug_assert!(false); false }, + PendingOutboundPayment::InvoiceReceived { .. } | + PendingOutboundPayment::StaticInvoiceReceived { .. } => { debug_assert!(false); false }, PendingOutboundPayment::Fulfilled { .. } => false, PendingOutboundPayment::Abandoned { .. } => false, }; @@ -278,6 +321,7 @@ impl PendingOutboundPayment { }, PendingOutboundPayment::AwaitingInvoice { .. } => 0, PendingOutboundPayment::InvoiceReceived { .. } => 0, + PendingOutboundPayment::StaticInvoiceReceived { .. } => 0, } } } @@ -394,8 +438,9 @@ impl_writeable_tlv_based_enum_legacy!(StaleExpiration, /// [`Event::PaymentFailed`]: crate::events::Event::PaymentFailed #[derive(Clone, Debug, PartialEq, Eq)] pub enum RetryableSendFailure { - /// The provided [`PaymentParameters::expiry_time`] indicated that the payment has expired. Note - /// that this error is *not* caused by [`Retry::Timeout`]. + /// The provided [`PaymentParameters::expiry_time`] indicated that the payment has expired. + #[cfg_attr(feature = "std", doc = "")] + #[cfg_attr(feature = "std", doc = "Note that this error is *not* caused by [`Retry::Timeout`].")] /// /// [`PaymentParameters::expiry_time`]: crate::routing::router::PaymentParameters::expiry_time PaymentExpired, @@ -497,6 +542,15 @@ pub enum Bolt12PaymentError { UnknownRequiredFeatures, /// The invoice was valid for the corresponding [`PaymentId`], but sending the payment failed. SendingFailed(RetryableSendFailure), + #[cfg(async_payments)] + /// Failed to create a blinded path back to ourselves. + /// + /// We attempted to initiate payment to a [`StaticInvoice`] but failed to create a reply path for + /// our [`HeldHtlcAvailable`] message. + /// + /// [`StaticInvoice`]: crate::offers::static_invoice::StaticInvoice + /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable + BlindedPathCreationFailed, } /// Indicates that we failed to send a payment probe. Further errors may be surfaced later via @@ -666,13 +720,19 @@ pub(super) struct SendAlongPathArgs<'a> { pub(super) struct OutboundPayments { pub(super) pending_outbound_payments: Mutex>, - pub(super) retry_lock: Mutex<()>, + awaiting_invoice: AtomicBool, + retry_lock: Mutex<()>, } impl OutboundPayments { - pub(super) fn new() -> Self { + pub(super) fn new(pending_outbound_payments: HashMap) -> Self { + let has_invoice_requests = pending_outbound_payments.values().any(|payment| { + matches!(payment, PendingOutboundPayment::AwaitingInvoice { retryable_invoice_request: Some(_), .. }) + }); + Self { - pending_outbound_payments: Mutex::new(new_hash_map()), + pending_outbound_payments: Mutex::new(pending_outbound_payments), + awaiting_invoice: AtomicBool::new(has_invoice_requests), retry_lock: Mutex::new(()), } } @@ -791,7 +851,7 @@ impl OutboundPayments { PendingOutboundPayment::AwaitingInvoice { retry_strategy: retry, max_total_routing_fee_msat: max_total_fee, .. } => { - retry_strategy = Some(*retry); + retry_strategy = *retry; max_total_routing_fee_msat = *max_total_fee; *entry.into_mut() = PendingOutboundPayment::InvoiceReceived { payment_hash, @@ -811,11 +871,42 @@ impl OutboundPayments { return Err(Bolt12PaymentError::UnknownRequiredFeatures); } - let mut payment_params = PaymentParameters::from_bolt12_invoice(&invoice); + let mut route_params = RouteParameters::from_payment_params_and_value( + PaymentParameters::from_bolt12_invoice(&invoice), invoice.amount_msats() + ); + if let Some(max_fee_msat) = max_total_routing_fee_msat { + route_params.max_total_routing_fee_msat = Some(max_fee_msat); + } + self.send_payment_for_bolt12_invoice_internal( + payment_id, payment_hash, None, route_params, retry_strategy, router, first_hops, + inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, best_block_height, + logger, pending_events, send_payment_along_path + ) + } + fn send_payment_for_bolt12_invoice_internal< + R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref + >( + &self, payment_id: PaymentId, payment_hash: PaymentHash, + keysend_preimage: Option, mut route_params: RouteParameters, + retry_strategy: Retry, router: &R, first_hops: Vec, inflight_htlcs: IH, + entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL, + secp_ctx: &Secp256k1, best_block_height: u32, logger: &L, + pending_events: &Mutex)>>, + send_payment_along_path: SP, + ) -> Result<(), Bolt12PaymentError> + where + R::Target: Router, + ES::Target: EntropySource, + NS::Target: NodeSigner, + NL::Target: NodeIdLookUp, + L::Target: Logger, + IH: Fn() -> InFlightHtlcs, + SP: Fn(SendAlongPathArgs) -> Result<(), APIError>, + { // Advance any blinded path where the introduction node is our node. if let Ok(our_node_id) = node_signer.get_node_id(Recipient::Node) { - for path in payment_params.payee.blinded_route_hints_mut().iter_mut() { + for path in route_params.payment_params.payee.blinded_route_hints_mut().iter_mut() { let introduction_node_id = match path.introduction_node() { IntroductionNode::NodeId(pubkey) => *pubkey, IntroductionNode::DirectedShortChannelId(direction, scid) => { @@ -831,15 +922,6 @@ impl OutboundPayments { } } - let amount_msat = invoice.amount_msats(); - let mut route_params = RouteParameters::from_payment_params_and_value( - payment_params, amount_msat - ); - - if let Some(max_fee_msat) = max_total_routing_fee_msat { - route_params.max_total_routing_fee_msat = Some(max_fee_msat); - } - let recipient_onion = RecipientOnionFields { payment_secret: None, payment_metadata: None, @@ -864,12 +946,13 @@ impl OutboundPayments { let payment_params = Some(route_params.payment_params.clone()); let (retryable_payment, onion_session_privs) = self.create_pending_payment( - payment_hash, recipient_onion.clone(), None, &route, - retry_strategy, payment_params, entropy_source, best_block_height + payment_hash, recipient_onion.clone(), keysend_preimage, &route, Some(retry_strategy), + payment_params, entropy_source, best_block_height ); match self.pending_outbound_payments.lock().unwrap().entry(payment_id) { hash_map::Entry::Occupied(entry) => match entry.get() { - PendingOutboundPayment::InvoiceReceived { .. } => { + PendingOutboundPayment::InvoiceReceived { .. } + | PendingOutboundPayment::StaticInvoiceReceived { .. } => { *entry.into_mut() = retryable_payment; }, _ => return Err(Bolt12PaymentError::DuplicateInvoice), @@ -878,7 +961,7 @@ impl OutboundPayments { } let result = self.pay_route_internal( - &route, payment_hash, &recipient_onion, None, payment_id, + &route, payment_hash, &recipient_onion, keysend_preimage, payment_id, Some(route_params.final_value_msat), onion_session_privs, node_signer, best_block_height, &send_payment_along_path ); @@ -896,6 +979,121 @@ impl OutboundPayments { Ok(()) } + #[cfg(async_payments)] + pub(super) fn static_invoice_received( + &self, invoice: &StaticInvoice, payment_id: PaymentId, features: Bolt12InvoiceFeatures, + best_block_height: u32, entropy_source: ES, + pending_events: &Mutex)>> + ) -> Result<(), Bolt12PaymentError> where ES::Target: EntropySource { + macro_rules! abandon_with_entry { + ($payment: expr, $reason: expr) => { + $payment.get_mut().mark_abandoned($reason); + if let PendingOutboundPayment::Abandoned { reason, .. } = $payment.get() { + if $payment.get().remaining_parts() == 0 { + pending_events.lock().unwrap().push_back((events::Event::PaymentFailed { + payment_id, + payment_hash: None, + reason: *reason, + }, None)); + $payment.remove(); + } + } + } + } + + match self.pending_outbound_payments.lock().unwrap().entry(payment_id) { + hash_map::Entry::Occupied(mut entry) => match entry.get() { + PendingOutboundPayment::AwaitingInvoice { + retry_strategy, retryable_invoice_request, max_total_routing_fee_msat, .. + } => { + let invreq = &retryable_invoice_request + .as_ref() + .ok_or(Bolt12PaymentError::UnexpectedInvoice)? + .invoice_request; + if !invoice.from_same_offer(invreq) { + return Err(Bolt12PaymentError::UnexpectedInvoice) + } + if invoice.invoice_features().requires_unknown_bits_from(&features) { + abandon_with_entry!(entry, PaymentFailureReason::UnknownRequiredFeatures); + return Err(Bolt12PaymentError::UnknownRequiredFeatures) + } + let amount_msat = match InvoiceBuilder::::amount_msats(invreq) { + Ok(amt) => amt, + Err(_) => { + // We check this during invoice request parsing, when constructing the invreq's + // contents from its TLV stream. + debug_assert!(false, "LDK requires an msat amount in either the invreq or the invreq's underlying offer"); + abandon_with_entry!(entry, PaymentFailureReason::UnexpectedError); + return Err(Bolt12PaymentError::UnknownRequiredFeatures) + } + }; + let keysend_preimage = PaymentPreimage(entropy_source.get_secure_random_bytes()); + let payment_hash = PaymentHash(Sha256::hash(&keysend_preimage.0).to_byte_array()); + let pay_params = PaymentParameters::from_static_invoice(invoice); + let mut route_params = RouteParameters::from_payment_params_and_value(pay_params, amount_msat); + route_params.max_total_routing_fee_msat = *max_total_routing_fee_msat; + + if let Err(()) = onion_utils::set_max_path_length( + &mut route_params, &RecipientOnionFields::spontaneous_empty(), Some(keysend_preimage), + best_block_height + ) { + abandon_with_entry!(entry, PaymentFailureReason::RouteNotFound); + return Err(Bolt12PaymentError::SendingFailed(RetryableSendFailure::OnionPacketSizeExceeded)) + } + + *entry.into_mut() = PendingOutboundPayment::StaticInvoiceReceived { + payment_hash, + keysend_preimage, + retry_strategy: *retry_strategy, + route_params, + }; + return Ok(()) + }, + _ => return Err(Bolt12PaymentError::DuplicateInvoice), + }, + hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice), + }; + } + + #[cfg(async_payments)] + pub(super) fn send_payment_for_static_invoice< + R: Deref, ES: Deref, NS: Deref, NL: Deref, IH, SP, L: Deref + >( + &self, payment_id: PaymentId, router: &R, first_hops: Vec, inflight_htlcs: IH, + entropy_source: &ES, node_signer: &NS, node_id_lookup: &NL, + secp_ctx: &Secp256k1, best_block_height: u32, logger: &L, + pending_events: &Mutex)>>, + send_payment_along_path: SP, + ) -> Result<(), Bolt12PaymentError> + where + R::Target: Router, + ES::Target: EntropySource, + NS::Target: NodeSigner, + NL::Target: NodeIdLookUp, + L::Target: Logger, + IH: Fn() -> InFlightHtlcs, + SP: Fn(SendAlongPathArgs) -> Result<(), APIError>, + { + let (payment_hash, keysend_preimage, route_params, retry_strategy) = + match self.pending_outbound_payments.lock().unwrap().entry(payment_id) { + hash_map::Entry::Occupied(entry) => match entry.get() { + PendingOutboundPayment::StaticInvoiceReceived { + payment_hash, route_params, retry_strategy, keysend_preimage, .. + } => { + (*payment_hash, *keysend_preimage, route_params.clone(), *retry_strategy) + }, + _ => return Err(Bolt12PaymentError::DuplicateInvoice), + }, + hash_map::Entry::Vacant(_) => return Err(Bolt12PaymentError::UnexpectedInvoice), + }; + + self.send_payment_for_bolt12_invoice_internal( + payment_id, payment_hash, Some(keysend_preimage), route_params, retry_strategy, router, + first_hops, inflight_htlcs, entropy_source, node_signer, node_id_lookup, secp_ctx, + best_block_height, logger, pending_events, send_payment_along_path + ) + } + pub(super) fn check_retry_payments( &self, router: &R, first_hops: FH, inflight_htlcs: IH, entropy_source: &ES, node_signer: &NS, best_block_height: u32, @@ -1175,6 +1373,11 @@ impl OutboundPayments { debug_assert!(false); return }, + PendingOutboundPayment::StaticInvoiceReceived { .. } => { + log_error!(logger, "Payment already initiating"); + debug_assert!(false); + return + }, PendingOutboundPayment::Fulfilled { .. } => { log_error!(logger, "Payment already completed"); return @@ -1393,16 +1596,20 @@ impl OutboundPayments { pub(super) fn add_new_awaiting_invoice( &self, payment_id: PaymentId, expiration: StaleExpiration, retry_strategy: Retry, - max_total_routing_fee_msat: Option + max_total_routing_fee_msat: Option, retryable_invoice_request: Option ) -> Result<(), ()> { let mut pending_outbounds = self.pending_outbound_payments.lock().unwrap(); match pending_outbounds.entry(payment_id) { hash_map::Entry::Occupied(_) => Err(()), hash_map::Entry::Vacant(entry) => { + if retryable_invoice_request.is_some() { + self.awaiting_invoice.store(true, Ordering::Release); + } entry.insert(PendingOutboundPayment::AwaitingInvoice { expiration, retry_strategy, max_total_routing_fee_msat, + retryable_invoice_request, }); Ok(()) @@ -1701,6 +1908,22 @@ impl OutboundPayments { true } }, + PendingOutboundPayment::StaticInvoiceReceived { route_params, payment_hash, .. } => { + let is_stale = + route_params.payment_params.expiry_time.unwrap_or(u64::MAX) < + duration_since_epoch.as_secs(); + if is_stale { + let fail_ev = events::Event::PaymentFailed { + payment_id: *payment_id, + payment_hash: Some(*payment_hash), + reason: Some(PaymentFailureReason::PaymentExpired) + }; + pending_events.push_back((fail_ev, None)); + false + } else { + true + } + }, _ => true, }); } @@ -1874,6 +2097,93 @@ impl OutboundPayments { pub fn clear_pending_payments(&self) { self.pending_outbound_payments.lock().unwrap().clear() } + + pub fn release_invoice_requests_awaiting_invoice(&self) -> Vec<(PaymentId, RetryableInvoiceRequest)> { + if !self.awaiting_invoice.load(Ordering::Acquire) { + return vec![]; + } + + let mut pending_outbound_payments = self.pending_outbound_payments.lock().unwrap(); + let invoice_requests = pending_outbound_payments + .iter_mut() + .filter_map(|(payment_id, payment)| { + if let PendingOutboundPayment::AwaitingInvoice { + retryable_invoice_request, .. + } = payment { + retryable_invoice_request.take().map(|retryable_invoice_request| { + (*payment_id, retryable_invoice_request) + }) + } else { + None + } + }) + .collect(); + + self.awaiting_invoice.store(false, Ordering::Release); + invoice_requests + } + + pub(super) fn insert_from_monitor_on_startup( + &self, payment_id: PaymentId, payment_hash: PaymentHash, session_priv_bytes: [u8; 32], + path: &Path, best_block_height: u32, logger: L + ) { + let path_amt = path.final_value_msat(); + let path_fee = path.fee_msat(); + + macro_rules! new_retryable { + () => { + PendingOutboundPayment::Retryable { + retry_strategy: None, + attempts: PaymentAttempts::new(), + payment_params: None, + session_privs: hash_set_from_iter([session_priv_bytes]), + payment_hash, + payment_secret: None, // only used for retries, and we'll never retry on startup + payment_metadata: None, // only used for retries, and we'll never retry on startup + keysend_preimage: None, // only used for retries, and we'll never retry on startup + custom_tlvs: Vec::new(), // only used for retries, and we'll never retry on startup + pending_amt_msat: path_amt, + pending_fee_msat: Some(path_fee), + total_msat: path_amt, + starting_block_height: best_block_height, + remaining_max_total_routing_fee_msat: None, // only used for retries, and we'll never retry on startup + } + } + } + + match self.pending_outbound_payments.lock().unwrap().entry(payment_id) { + hash_map::Entry::Occupied(mut entry) => { + let newly_added = match entry.get() { + PendingOutboundPayment::AwaitingInvoice { .. } | + PendingOutboundPayment::InvoiceReceived { .. } | + PendingOutboundPayment::StaticInvoiceReceived { .. } => + { + // If we've reached this point, it means we initiated a payment to a BOLT 12 invoice and + // locked the htlc(s) into the `ChannelMonitor`(s), but failed to persist the + // `ChannelManager` after transitioning from this state to `Retryable` prior to shutdown. + // Therefore, we need to move this payment to `Retryable` now to avoid double-paying if + // the recipient sends a duplicate invoice or release_held_htlc onion message. + *entry.get_mut() = new_retryable!(); + true + }, + PendingOutboundPayment::Legacy { .. } | + PendingOutboundPayment::Retryable { .. } | + PendingOutboundPayment::Fulfilled { .. } | + PendingOutboundPayment::Abandoned { .. } => + { + entry.get_mut().insert(session_priv_bytes, &path) + } + }; + log_info!(logger, "{} a pending payment path for {} msat for session priv {} on an existing pending payment with payment hash {}", + if newly_added { "Added" } else { "Had" }, path_amt, log_bytes!(session_priv_bytes), payment_hash); + }, + hash_map::Entry::Vacant(entry) => { + entry.insert(new_retryable!()); + log_info!(logger, "Added a pending payment for {} msat with payment hash {} for path with session priv {}", + path_amt, payment_hash, log_bytes!(session_priv_bytes)); + } + } + } } /// Returns whether a payment with the given [`PaymentHash`] and [`PaymentId`] is, in fact, a @@ -1929,12 +2239,21 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment, (0, expiration, required), (2, retry_strategy, required), (4, max_total_routing_fee_msat, option), + (5, retryable_invoice_request, option), }, (7, InvoiceReceived) => { (0, payment_hash, required), (2, retry_strategy, required), (4, max_total_routing_fee_msat, option), }, + // Added in 0.0.125. Prior versions will drop these outbounds on downgrade, which is safe because + // no HTLCs are in-flight. + (9, StaticInvoiceReceived) => { + (0, payment_hash, required), + (2, keysend_preimage, required), + (4, retry_strategy, required), + (6, route_params, required), + }, ); #[cfg(test)] @@ -1946,11 +2265,11 @@ mod tests { use crate::blinded_path::EmptyNodeIdLookUp; use crate::events::{Event, PathFailure, PaymentFailureReason}; - use crate::ln::types::PaymentHash; + use crate::ln::types::{PaymentHash, PaymentPreimage}; use crate::ln::channelmanager::{PaymentId, RecipientOnionFields}; use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{ErrorAction, LightningError}; - use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, Retry, RetryableSendFailure, StaleExpiration}; + use crate::ln::outbound_payment::{Bolt12PaymentError, OutboundPayments, PendingOutboundPayment, Retry, RetryableSendFailure, StaleExpiration}; #[cfg(feature = "std")] use crate::offers::invoice::DEFAULT_RELATIVE_EXPIRY; use crate::offers::offer::OfferBuilder; @@ -1959,6 +2278,7 @@ mod tests { use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters}; use crate::sync::{Arc, Mutex, RwLock}; use crate::util::errors::APIError; + use crate::util::hash_tables::new_hash_map; use crate::util::test_utils; use alloc::collections::VecDeque; @@ -1993,7 +2313,7 @@ mod tests { } #[cfg(feature = "std")] fn do_fails_paying_after_expiration(on_retry: bool) { - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let logger = test_utils::TestLogger::new(); let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &logger)); let scorer = RwLock::new(test_utils::TestScorer::new()); @@ -2037,7 +2357,7 @@ mod tests { do_find_route_error(true); } fn do_find_route_error(on_retry: bool) { - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let logger = test_utils::TestLogger::new(); let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &logger)); let scorer = RwLock::new(test_utils::TestScorer::new()); @@ -2076,7 +2396,7 @@ mod tests { #[test] fn initial_send_payment_path_failed_evs() { - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let logger = test_utils::TestLogger::new(); let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, &logger)); let scorer = RwLock::new(test_utils::TestScorer::new()); @@ -2158,7 +2478,7 @@ mod tests { #[test] fn removes_stale_awaiting_invoice_using_absolute_timeout() { let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let absolute_expiry = 100; let tick_interval = 10; @@ -2167,7 +2487,7 @@ mod tests { assert!(!outbound_payments.has_pending_payments()); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2197,14 +2517,14 @@ mod tests { assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_err() ); } @@ -2212,7 +2532,7 @@ mod tests { #[test] fn removes_stale_awaiting_invoice_using_timer_ticks() { let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let timer_ticks = 3; let expiration = StaleExpiration::TimerTicks(timer_ticks); @@ -2220,7 +2540,7 @@ mod tests { assert!(!outbound_payments.has_pending_payments()); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2250,14 +2570,14 @@ mod tests { assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_err() ); } @@ -2265,14 +2585,14 @@ mod tests { #[test] fn removes_abandoned_awaiting_invoice() { let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); assert!(!outbound_payments.has_pending_payments()); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2302,13 +2622,13 @@ mod tests { let keys_manager = test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet); let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), None + payment_id, expiration, Retry::Attempts(0), None, None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2355,7 +2675,7 @@ mod tests { let keys_manager = test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet); let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); @@ -2372,7 +2692,7 @@ mod tests { assert!( outbound_payments.add_new_awaiting_invoice( payment_id, expiration, Retry::Attempts(0), - Some(invoice.amount_msats() / 100 + 50_000) + Some(invoice.amount_msats() / 100 + 50_000), None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2416,7 +2736,7 @@ mod tests { let keys_manager = test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet); let pending_events = Mutex::new(VecDeque::new()); - let outbound_payments = OutboundPayments::new(); + let outbound_payments = OutboundPayments::new(new_hash_map()); let payment_id = PaymentId([0; 32]); let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100)); @@ -2472,7 +2792,7 @@ mod tests { assert!( outbound_payments.add_new_awaiting_invoice( - payment_id, expiration, Retry::Attempts(0), Some(1234) + payment_id, expiration, Retry::Attempts(0), Some(1234), None, ).is_ok() ); assert!(outbound_payments.has_pending_payments()); @@ -2499,4 +2819,89 @@ mod tests { assert!(outbound_payments.has_pending_payments()); assert!(pending_events.lock().unwrap().is_empty()); } + + #[test] + fn time_out_unreleased_async_payments() { + let pending_events = Mutex::new(VecDeque::new()); + let outbound_payments = OutboundPayments::new(new_hash_map()); + let payment_id = PaymentId([0; 32]); + let absolute_expiry = 60; + + let mut outbounds = outbound_payments.pending_outbound_payments.lock().unwrap(); + let payment_params = PaymentParameters::from_node_id(test_utils::pubkey(42), 0) + .with_expiry_time(absolute_expiry); + let route_params = RouteParameters { + payment_params, + final_value_msat: 0, + max_total_routing_fee_msat: None, + }; + let payment_hash = PaymentHash([0; 32]); + let outbound = PendingOutboundPayment::StaticInvoiceReceived { + payment_hash, + keysend_preimage: PaymentPreimage([0; 32]), + retry_strategy: Retry::Attempts(0), + route_params, + }; + outbounds.insert(payment_id, outbound); + core::mem::drop(outbounds); + + // The payment will not be removed if it isn't expired yet. + outbound_payments.remove_stale_payments(Duration::from_secs(absolute_expiry), &pending_events); + let outbounds = outbound_payments.pending_outbound_payments.lock().unwrap(); + assert_eq!(outbounds.len(), 1); + let events = pending_events.lock().unwrap(); + assert_eq!(events.len(), 0); + core::mem::drop(outbounds); + core::mem::drop(events); + + outbound_payments.remove_stale_payments(Duration::from_secs(absolute_expiry + 1), &pending_events); + let outbounds = outbound_payments.pending_outbound_payments.lock().unwrap(); + assert_eq!(outbounds.len(), 0); + let events = pending_events.lock().unwrap(); + assert_eq!(events.len(), 1); + assert_eq!(events[0], (Event::PaymentFailed { + payment_hash: Some(payment_hash), + payment_id, + reason: Some(PaymentFailureReason::PaymentExpired), + }, None)); + } + + #[test] + fn abandon_unreleased_async_payment() { + let pending_events = Mutex::new(VecDeque::new()); + let outbound_payments = OutboundPayments::new(new_hash_map()); + let payment_id = PaymentId([0; 32]); + let absolute_expiry = 60; + + let mut outbounds = outbound_payments.pending_outbound_payments.lock().unwrap(); + let payment_params = PaymentParameters::from_node_id(test_utils::pubkey(42), 0) + .with_expiry_time(absolute_expiry); + let route_params = RouteParameters { + payment_params, + final_value_msat: 0, + max_total_routing_fee_msat: None, + }; + let payment_hash = PaymentHash([0; 32]); + let outbound = PendingOutboundPayment::StaticInvoiceReceived { + payment_hash, + keysend_preimage: PaymentPreimage([0; 32]), + retry_strategy: Retry::Attempts(0), + route_params, + }; + outbounds.insert(payment_id, outbound); + core::mem::drop(outbounds); + + outbound_payments.abandon_payment( + payment_id, PaymentFailureReason::UserAbandoned, &pending_events + ); + let outbounds = outbound_payments.pending_outbound_payments.lock().unwrap(); + assert_eq!(outbounds.len(), 0); + let events = pending_events.lock().unwrap(); + assert_eq!(events.len(), 1); + assert_eq!(events[0], (Event::PaymentFailed { + payment_hash: Some(payment_hash), + payment_id, + reason: Some(PaymentFailureReason::UserAbandoned), + }, None)); + } } diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 60dd82b75b0..eac2a35c6a1 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -122,7 +122,7 @@ fn mpp_retry() { // Add the HTLC along the first hop. let fail_path_msgs_1 = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); let send_event = SendEvent::from_event(fail_path_msgs_1); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], &send_event.commitment_msg, false); // Attempt to forward the payment and complete the 2nd path's failure. @@ -134,7 +134,7 @@ fn mpp_retry() { assert!(htlc_updates.update_fulfill_htlcs.is_empty()); assert!(htlc_updates.update_fail_malformed_htlcs.is_empty()); check_added_monitors!(nodes[2], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], htlc_updates.commitment_signed, false); let mut events = nodes[0].node.get_and_clear_pending_events(); match events[1] { @@ -226,7 +226,7 @@ fn mpp_retry_overpay() { // Add the HTLC along the first hop. let fail_path_msgs_1 = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events); let send_event = SendEvent::from_event(fail_path_msgs_1); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], &send_event.commitment_msg, false); // Attempt to forward the payment and complete the 2nd path's failure. @@ -242,7 +242,7 @@ fn mpp_retry_overpay() { assert!(htlc_updates.update_fulfill_htlcs.is_empty()); assert!(htlc_updates.update_fail_malformed_htlcs.is_empty()); check_added_monitors!(nodes[2], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], htlc_updates.commitment_signed, false); let mut events = nodes[0].node.get_and_clear_pending_events(); @@ -331,7 +331,7 @@ fn do_mpp_receive_timeout(send_partial_mpp: bool) { expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], vec![HTLCDestination::FailedPayment { payment_hash }]); let htlc_fail_updates_3_1 = get_htlc_update_msgs!(nodes[3], nodes[1].node.get_our_node_id()); assert_eq!(htlc_fail_updates_3_1.update_fail_htlcs.len(), 1); - nodes[1].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &htlc_fail_updates_3_1.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &htlc_fail_updates_3_1.update_fail_htlcs[0]); check_added_monitors!(nodes[3], 1); commitment_signed_dance!(nodes[1], nodes[3], htlc_fail_updates_3_1.commitment_signed, false); @@ -339,7 +339,7 @@ fn do_mpp_receive_timeout(send_partial_mpp: bool) { expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_3_id }]); let htlc_fail_updates_1_0 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(htlc_fail_updates_1_0.update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_fail_updates_1_0.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_fail_updates_1_0.update_fail_htlcs[0]); check_added_monitors!(nodes[1], 1); commitment_signed_dance!(nodes[0], nodes[1], htlc_fail_updates_1_0.commitment_signed, false); @@ -415,7 +415,7 @@ fn do_test_keysend_payments(public_node: bool, with_retry: bool) { } check_added_monitors!(nodes[0], 1); let send_event = SendEvent::from_node(&nodes[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); do_commitment_signed_dance(&nodes[1], &nodes[0], &send_event.commitment_msg, false, false); expect_pending_htlcs_forwardable!(nodes[1]); // Previously, a refactor caused us to stop including the payment preimage in the onion which @@ -510,14 +510,14 @@ fn test_reject_mpp_keysend_htlc() { let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let update_add_0 = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_0); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_0); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors!(&nodes[1], 1); let update_1 = get_htlc_update_msgs!(nodes[1], nodes[3].node.get_our_node_id()); let update_add_1 = update_1.update_add_htlcs[0].clone(); - nodes[3].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_1); + nodes[3].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add_1); commitment_signed_dance!(nodes[3], nodes[1], update_1.commitment_signed, false, true); assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty()); @@ -552,14 +552,14 @@ fn test_reject_mpp_keysend_htlc() { let update_2 = get_htlc_update_msgs!(nodes[0], nodes[2].node.get_our_node_id()); let update_add_2 = update_2.update_add_htlcs[0].clone(); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_2); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_2); commitment_signed_dance!(nodes[2], nodes[0], &update_2.commitment_signed, false, true); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors!(&nodes[2], 1); let update_3 = get_htlc_update_msgs!(nodes[2], nodes[3].node.get_our_node_id()); let update_add_3 = update_3.update_add_htlcs[0].clone(); - nodes[3].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &update_add_3); + nodes[3].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &update_add_3); commitment_signed_dance!(nodes[3], nodes[2], update_3.commitment_signed, false, true); assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty()); @@ -586,13 +586,13 @@ fn test_reject_mpp_keysend_htlc() { // Fail back along nodes[2] let update_fail_0 = get_htlc_update_msgs!(&nodes[3], &nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &update_fail_0.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &update_fail_0.update_fail_htlcs[0]); commitment_signed_dance!(nodes[2], nodes[3], update_fail_0.commitment_signed, false); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_4_channel_id }]); check_added_monitors!(nodes[2], 1); let update_fail_1 = get_htlc_update_msgs!(nodes[2], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &update_fail_1.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &update_fail_1.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], update_fail_1.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], payment_hash, true, PaymentFailedConditions::new()); @@ -617,8 +617,8 @@ fn no_pending_leak_on_initial_send_failure() { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); unwrap_send_err!(nodes[0].node.send_payment_with_route(route, payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0) @@ -672,10 +672,10 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { // We relay the payment to nodes[1] while its disconnected from nodes[2], causing the payment // to be returned immediately to nodes[0], without having nodes[2] fail the inbound payment // which would prevent retry. - nodes[1].node.peer_disconnected(&nodes[2].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true); // nodes[1] now immediately fails the HTLC as the next-hop channel is disconnected let _ = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -708,25 +708,25 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { } check_added_monitors!(nodes[0], 1); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); // Now nodes[1] should send a channel reestablish, which nodes[0] will respond to with an // error, as the channel has hit the chain. - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); let as_err = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(as_err.len(), 2); match as_err[1] { MessageSendEvent::HandleError { node_id, action: msgs::ErrorAction::SendErrorMessage { ref msg } } => { assert_eq!(node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), msg); + nodes[1].node.handle_error(nodes[0].node.get_our_node_id(), msg); check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) }, [nodes[0].node.get_our_node_id()], 100000); check_added_monitors!(nodes[1], 1); @@ -743,7 +743,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { expect_payment_claimed!(nodes[2], payment_hash_1, 1_000_000); let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); check_added_monitors!(nodes[1], 1); commitment_signed_dance!(nodes[1], nodes[2], htlc_fulfill_updates.commitment_signed, false); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, true, false); @@ -882,7 +882,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode(); reload_node!(nodes[0], test_default_channel_config(), nodes_0_serialized, &[&chan_0_monitor_serialized], first_persister, first_new_chain_monitor, first_nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // On reload, the ChannelManager should realize it is stale compared to the ChannelMonitor and // force-close the channel. @@ -893,25 +893,25 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { assert_eq!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0).len(), 1); check_added_monitors!(nodes[0], 1); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); // Now nodes[1] should send a channel reestablish, which nodes[0] will respond to with an // error, as the channel has hit the chain. - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); let as_err = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(as_err.len(), 2); let bs_commitment_tx; match as_err[1] { MessageSendEvent::HandleError { node_id, action: msgs::ErrorAction::SendErrorMessage { ref msg } } => { assert_eq!(node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), msg); + nodes[1].node.handle_error(nodes[0].node.get_our_node_id(), msg); check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) } , [nodes[0].node.get_our_node_id()], 100000); check_added_monitors!(nodes[1], 1); @@ -929,7 +929,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { check_added_monitors!(nodes[2], 1); let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[2], htlc_fulfill_updates.commitment_signed, false); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_id_2 }]); @@ -989,7 +989,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { assert!(!nodes[0].node.get_and_clear_pending_msg_events().is_empty()); reload_node!(nodes[0], test_default_channel_config(), nodes_0_serialized, &[&chan_0_monitor_serialized, &chan_1_monitor_serialized], second_persister, second_new_chain_monitor, second_nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); nodes[0].node.test_process_background_events(); check_added_monitors(&nodes[0], 1); @@ -1019,7 +1019,7 @@ fn do_test_completed_payment_not_retryable_on_reload(use_dust: bool) { // Check that after reload we can send the payment again (though we shouldn't, since it was // claimed previously). reload_node!(nodes[0], test_default_channel_config(), nodes_0_serialized, &[&chan_0_monitor_serialized, &chan_1_monitor_serialized], third_persister, third_new_chain_monitor, third_nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); nodes[0].node.test_process_background_events(); check_added_monitors(&nodes[0], 1); @@ -1067,8 +1067,8 @@ fn do_test_dup_htlc_onchain_doesnt_fail_on_reload(persist_manager_post_event: bo check_added_monitors!(nodes[0], 1); check_closed_event!(nodes[0], 1, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) }, [nodes[1].node.get_our_node_id()], 100000); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Connect blocks until the CLTV timeout is up so that we get an HTLC-Timeout transaction connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1); @@ -1203,20 +1203,20 @@ fn test_fulfill_restart_failure() { expect_payment_claimed!(nodes[1], payment_hash, 100_000); let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); // Now reload nodes[1]... reload_node!(nodes[1], &chan_manager_serialized, &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_1_deserialized); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); nodes[1].node.fail_htlc_backwards(&payment_hash); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::FailedPayment { payment_hash }]); check_added_monitors!(nodes[1], 1); let htlc_fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_fail_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], htlc_fail_updates.commitment_signed, false); // nodes[0] shouldn't generate any events here, while it just got a payment failure completion // it had already considered the payment fulfilled, and now they just got free money. @@ -1334,7 +1334,7 @@ fn failed_probe_yields_event() { check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let probe_event = SendEvent::from_commitment_update(nodes[1].node.get_our_node_id(), updates); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &probe_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &probe_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], probe_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1344,7 +1344,7 @@ fn failed_probe_yields_event() { let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); // Skip the PendingHTLCsForwardable event let _events = nodes[1].node.get_and_clear_pending_events(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); check_added_monitors!(nodes[0], 0); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false); @@ -1382,7 +1382,7 @@ fn onchain_failed_probe_yields_event() { check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let probe_event = SendEvent::from_commitment_update(nodes[1].node.get_our_node_id(), updates); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &probe_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &probe_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], probe_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -1920,7 +1920,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &payment_event.commitment_msg, false, true); // Check that we generate the PaymentIntercepted event when an intercept forward is detected. @@ -1953,7 +1953,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { check_added_monitors!(&nodes[1], 1); assert!(update_fail.update_fail_htlcs.len() == 1); let fail_msg = update_fail.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_fail.commitment_signed, false); // Ensure the payment fails with the expected error. @@ -1988,7 +1988,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], &payment_event.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[2]); @@ -2031,7 +2031,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { assert!(htlc_timeout_updates.update_fail_malformed_htlcs.is_empty()); assert!(htlc_timeout_updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_timeout_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], htlc_timeout_updates.commitment_signed, false); expect_payment_failed!(nodes[0], payment_hash, false, 0x2000 | 2, []); @@ -2104,7 +2104,7 @@ fn do_accept_underpaying_htlcs_config(num_mpp_parts: usize) { // Forward the intercepted payments. for (idx, ev) in events.into_iter().enumerate() { - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &ev.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &ev.msgs[0]); do_commitment_signed_dance(&nodes[1], &nodes[0], &ev.commitment_msg, false, true); let events = nodes[1].node.get_and_clear_pending_events(); @@ -2131,7 +2131,7 @@ fn do_accept_underpaying_htlcs_config(num_mpp_parts: usize) { assert_eq!(events.len(), 1); SendEvent::from_event(events.remove(0)) }; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event.commitment_msg, false, true); if idx == num_mpp_parts - 1 { expect_pending_htlcs_forwardable!(nodes[2]); @@ -2233,7 +2233,7 @@ fn do_automatic_retries(test: AutoRetry) { check_added_monitors!(nodes[0], 1); let update_0 = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); let mut update_add = update_0.update_add_htlcs[0].clone(); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add); commitment_signed_dance!(nodes[1], nodes[0], &update_0.commitment_signed, false, true); expect_pending_htlcs_forwardable_ignore!(nodes[1]); nodes[1].node.process_pending_htlc_forwards(); @@ -2247,7 +2247,7 @@ fn do_automatic_retries(test: AutoRetry) { check_added_monitors!(&nodes[1], 1); assert!(update_1.update_fail_htlcs.len() == 1); let fail_msg = update_1.update_fail_htlcs[0].clone(); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &fail_msg); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &fail_msg); commitment_signed_dance!(nodes[0], nodes[1], update_1.commitment_signed, false); // Ensure the attempt fails and a new PendingHTLCsForwardable event is generated for the retry @@ -2551,36 +2551,36 @@ fn auto_retry_partial_failure() { assert_eq!(msg_events.len(), 1); let mut payment_event = SendEvent::from_event(msg_events.remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_first_raa, bs_first_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); check_added_monitors!(nodes[0], 1); let as_second_htlc_updates = SendEvent::from_node(&nodes[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_first_cs); check_added_monitors!(nodes[0], 1); let as_first_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_second_htlc_updates.msgs[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_second_htlc_updates.msgs[1]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_htlc_updates.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_second_htlc_updates.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_second_htlc_updates.msgs[1]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_second_htlc_updates.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_second_raa, bs_second_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_cs); check_added_monitors!(nodes[0], 1); let as_second_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); expect_pending_htlcs_forwardable_ignore!(nodes[1]); @@ -2591,38 +2591,38 @@ fn auto_retry_partial_failure() { let bs_claim_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); assert_eq!(bs_claim_update.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_claim_update.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_claim_update.update_fulfill_htlcs[0]); expect_payment_sent(&nodes[0], payment_preimage, None, false, false); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_claim_update.commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_claim_update.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_third_raa, as_third_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_third_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_third_raa); check_added_monitors!(nodes[1], 4); let bs_second_claim_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_third_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_third_cs); check_added_monitors!(nodes[1], 1); let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_third_raa); check_added_monitors!(nodes[0], 1); expect_payment_path_successful!(nodes[0]); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_claim_update.update_fulfill_htlcs[0]); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_claim_update.update_fulfill_htlcs[1]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_claim_update.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_second_claim_update.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &bs_second_claim_update.update_fulfill_htlcs[1]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_claim_update.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_fourth_raa, as_fourth_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_fourth_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_fourth_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_fourth_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_fourth_cs); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 2); @@ -2715,7 +2715,7 @@ fn fails_paying_after_rejected_by_payee() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -2990,59 +2990,59 @@ fn no_extra_retries_on_back_to_back_fail() { check_added_monitors!(nodes[0], 1); assert_eq!(htlc_updates.msgs.len(), 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &htlc_updates.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &htlc_updates.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &htlc_updates.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &htlc_updates.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_first_raa, bs_first_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); check_added_monitors!(nodes[0], 1); let second_htlc_updates = SendEvent::from_node(&nodes[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_first_cs); check_added_monitors!(nodes[0], 1); let as_first_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &second_htlc_updates.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &second_htlc_updates.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &second_htlc_updates.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &second_htlc_updates.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); check_added_monitors!(nodes[1], 1); let bs_fail_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_fail_update.commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_fail_update.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_second_raa, as_third_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); let bs_second_fail_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_third_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_third_cs); check_added_monitors!(nodes[1], 1); let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_second_fail_update.update_fail_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_fail_update.commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_second_fail_update.update_fail_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_second_fail_update.commitment_signed); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_third_raa); check_added_monitors!(nodes[0], 1); let (as_third_raa, as_fourth_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_third_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_third_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_fourth_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_fourth_cs); check_added_monitors!(nodes[1], 1); let bs_fourth_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_fourth_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_fourth_raa); check_added_monitors!(nodes[0], 1); // At this point A has sent two HTLCs which both failed due to lack of fee. It now has two @@ -3082,10 +3082,10 @@ fn no_extra_retries_on_back_to_back_fail() { let retry_htlc_updates = SendEvent::from_node(&nodes[0]); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &retry_htlc_updates.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &retry_htlc_updates.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &retry_htlc_updates.commitment_msg, false, true); let bs_fail_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], &bs_fail_update.commitment_signed, false, true); let mut events = nodes[0].node.get_and_clear_pending_events(); @@ -3195,45 +3195,45 @@ fn test_simple_partial_retry() { check_added_monitors!(nodes[0], 1); assert_eq!(htlc_updates.msgs.len(), 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &htlc_updates.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &htlc_updates.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &htlc_updates.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &htlc_updates.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_first_raa, bs_first_cs) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_first_raa); check_added_monitors!(nodes[0], 1); let second_htlc_updates = SendEvent::from_node(&nodes[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_first_cs); check_added_monitors!(nodes[0], 1); let as_first_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &second_htlc_updates.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &second_htlc_updates.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &second_htlc_updates.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &second_htlc_updates.commitment_msg); check_added_monitors!(nodes[1], 1); let bs_second_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_first_raa); check_added_monitors!(nodes[1], 1); let bs_fail_update = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_second_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_second_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_fail_update.commitment_signed); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_fail_update.update_fail_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_fail_update.commitment_signed); check_added_monitors!(nodes[0], 1); let (as_second_raa, as_third_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &as_second_raa); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_third_cs); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_third_cs); check_added_monitors!(nodes[1], 1); let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_third_raa); check_added_monitors!(nodes[0], 1); let mut events = nodes[0].node.get_and_clear_pending_events(); @@ -3254,15 +3254,15 @@ fn test_simple_partial_retry() { let retry_htlc_updates = SendEvent::from_node(&nodes[0]); check_added_monitors!(nodes[0], 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &retry_htlc_updates.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &retry_htlc_updates.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &retry_htlc_updates.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors!(nodes[1], 1); let bs_forward_update = get_htlc_update_msgs!(nodes[1], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[0]); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[1]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_forward_update.update_add_htlcs[1]); commitment_signed_dance!(nodes[2], nodes[1], &bs_forward_update.commitment_signed, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -3396,7 +3396,7 @@ fn test_threaded_payment_retries() { let send_event = SendEvent::from_event(send_msg_events.pop().unwrap()); assert_eq!(send_event.msgs.len(), 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], send_event.commitment_msg, false, true); // Note that we only push one route into `expect_find_route` at a time, because that's all @@ -3412,14 +3412,14 @@ fn test_threaded_payment_retries() { nodes[0].router.expect_find_route(new_route_params, Ok(route.clone())); let bs_fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_fail_updates.update_fail_htlcs[0]); // The "normal" commitment_signed_dance delivers the final RAA and then calls // `check_added_monitors` to ensure only the one RAA-generated monitor update was created. // This races with our other threads which may generate an add-HTLCs commitment update via // `process_pending_htlc_forwards`. Instead, we defer the monitor update check until after // *we've* called `process_pending_htlc_forwards` when its guaranteed to have two updates. let last_raa = commitment_signed_dance!(nodes[0], nodes[1], bs_fail_updates.commitment_signed, false, true, false, true); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &last_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &last_raa); let cur_time = Instant::now(); if cur_time > end_time { @@ -3469,12 +3469,12 @@ fn do_no_missing_sent_on_reload(persist_manager_with_payment: bool, at_midpoint: if at_midpoint { let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[0], 1); } else { let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], htlc_fulfill_updates.commitment_signed, false); // Ignore the PaymentSent event which is now pending on nodes[0] - if we were to handle it we'd // be expected to ignore the eventual conflicting PaymentFailed, but by not looking at it we @@ -3646,7 +3646,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) { check_added_monitors(&nodes[1], 1); assert_eq!(bs_claims.len(), 1); if let MessageSendEvent::UpdateHTLCs { updates, .. } = &bs_claims[0] { - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false, true); } else { panic!(); } @@ -3655,7 +3655,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) { let ds_claim_msgs = nodes[3].node.get_and_clear_pending_msg_events(); assert_eq!(ds_claim_msgs.len(), 1); let cs_claim_msgs = if let MessageSendEvent::UpdateHTLCs { updates, .. } = &ds_claim_msgs[0] { - nodes[2].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[2].node.handle_update_fulfill_htlc(nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); let cs_claim_msgs = nodes[2].node.get_and_clear_pending_msg_events(); check_added_monitors(&nodes[2], 1); commitment_signed_dance!(nodes[2], nodes[3], updates.commitment_signed, false, true); @@ -3665,7 +3665,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) { assert_eq!(cs_claim_msgs.len(), 1); if let MessageSendEvent::UpdateHTLCs { updates, .. } = &cs_claim_msgs[0] { - nodes[0].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], updates.commitment_signed, false, true); } else { panic!(); } @@ -3724,7 +3724,7 @@ fn do_test_custom_tlvs(spontaneous: bool, even_tlvs: bool, known_tlvs: bool) { let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events); let mut payment_event = SendEvent::from_event(ev); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(&nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -3797,7 +3797,7 @@ fn test_retry_custom_tlvs() { let htlc_updates = get_htlc_update_msgs(&nodes[0], &nodes[1].node.get_our_node_id()); let msgs::CommitmentUpdate { update_add_htlcs, commitment_signed, .. } = htlc_updates; assert_eq!(update_add_htlcs.len(), 1); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], commitment_signed, false); // Attempt to forward the payment and complete the path's failure. @@ -3812,7 +3812,7 @@ fn test_retry_custom_tlvs() { let htlc_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); let msgs::CommitmentUpdate { update_fail_htlcs, commitment_signed, .. } = htlc_updates; assert_eq!(update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false); let mut events = nodes[0].node.get_and_clear_pending_events(); @@ -3946,7 +3946,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec)>, second_tlvs: assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -3956,7 +3956,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec)>, second_tlvs: assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[3].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[3].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &payment_event.msgs[0]); check_added_monitors!(nodes[3], 0); commitment_signed_dance!(nodes[3], nodes[2], payment_event.commitment_msg, true, true); } @@ -3986,7 +3986,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec)>, second_tlvs: check_added_monitors!(nodes[3], 1); let fail_updates_1 = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]); commitment_signed_dance!(nodes[2], nodes[3], fail_updates_1.commitment_signed, false); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2], vec![ @@ -3997,7 +3997,7 @@ fn do_test_custom_tlvs_consistency(first_tlvs: Vec<(u64, Vec)>, second_tlvs: check_added_monitors!(nodes[2], 1); let fail_updates_2 = get_htlc_update_msgs!(nodes[2], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &fail_updates_2.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &fail_updates_2.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], fail_updates_2.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], our_payment_hash, true, @@ -4055,27 +4055,27 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { } else { (&second_send, &first_send) }; - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &b_recv_ev.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &b_recv_ev.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], b_recv_ev.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[1]); check_added_monitors(&nodes[1], 1); let b_forward_ev = SendEvent::from_node(&nodes[1]); - nodes[3].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &b_forward_ev.msgs[0]); + nodes[3].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &b_forward_ev.msgs[0]); commitment_signed_dance!(nodes[3], nodes[1], b_forward_ev.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[3]); // Before delivering the second MPP HTLC to nodes[2], disconnect nodes[2] and nodes[3], which // will result in nodes[2] failing the HTLC back. - nodes[2].node.peer_disconnected(&nodes[3].node.get_our_node_id()); - nodes[3].node.peer_disconnected(&nodes[2].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[3].node.get_our_node_id()); + nodes[3].node.peer_disconnected(nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &c_recv_ev.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &c_recv_ev.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], c_recv_ev.commitment_msg, false, true); let cs_fail = get_htlc_update_msgs(&nodes[2], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &cs_fail.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &cs_fail.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], cs_fail.commitment_signed, false, true); let payment_fail_retryable_evs = nodes[0].node.get_and_clear_pending_events(); @@ -4096,7 +4096,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { let mon_cd = get_monitor!(nodes[3], chan_id_cd).encode(); reload_node!(nodes[3], config, &nodes[3].node.encode(), &[&mon_bd, &mon_cd], persister, new_chain_monitor, nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[3].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[3].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[1], &nodes[3])); } let mut reconnect_args = ReconnectArgs::new(&nodes[2], &nodes[3]); @@ -4111,14 +4111,14 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { nodes[0].node.process_pending_htlc_forwards(); check_added_monitors(&nodes[0], 1); let as_resend = SendEvent::from_node(&nodes[0]); - nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_resend.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_resend.msgs[0]); commitment_signed_dance!(nodes[2], nodes[0], as_resend.commitment_msg, false, true); expect_pending_htlcs_forwardable!(nodes[2]); check_added_monitors(&nodes[2], 1); let cs_forward = SendEvent::from_node(&nodes[2]); let cd_channel_used = cs_forward.msgs[0].channel_id; - nodes[3].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &cs_forward.msgs[0]); + nodes[3].node.handle_update_add_htlc(nodes[2].node.get_our_node_id(), &cs_forward.msgs[0]); commitment_signed_dance!(nodes[3], nodes[2], cs_forward.commitment_msg, false, true); // Finally, check that nodes[3] does the correct thing - either accepting the payment or, if @@ -4134,7 +4134,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) { check_added_monitors(&nodes[3], 1); let ds_fail = get_htlc_update_msgs(&nodes[3], &nodes[2].node.get_our_node_id()); - nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &ds_fail.update_fail_htlcs[0]); + nodes[2].node.handle_update_fail_htlc(nodes[3].node.get_our_node_id(), &ds_fail.update_fail_htlcs[0]); commitment_signed_dance!(nodes[2], nodes[3], ds_fail.commitment_signed, false, true); expect_pending_htlcs_forwardable_conditions(nodes[2].node.get_and_clear_pending_events(), &[HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: cd_channel_used }]); @@ -4208,7 +4208,7 @@ fn test_htlc_forward_considers_anchor_outputs_value() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let mut update_add_htlc = if let MessageSendEvent::UpdateHTLCs { updates, .. } = events.pop().unwrap() { - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); check_added_monitors(&nodes[1], 0); commitment_signed_dance!(nodes[1], nodes[0], &updates.commitment_signed, false); updates.update_add_htlcs[0].clone() @@ -4227,7 +4227,7 @@ fn test_htlc_forward_considers_anchor_outputs_value() { let mut events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); if let MessageSendEvent::UpdateHTLCs { updates, .. } = events.pop().unwrap() { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); check_added_monitors(&nodes[0], 0); commitment_signed_dance!(nodes[0], nodes[1], &updates.commitment_signed, false); } else { @@ -4239,7 +4239,7 @@ fn test_htlc_forward_considers_anchor_outputs_value() { // Assume that the forwarding node did forward it, and make sure the recipient rejects it as an // invalid update and closes the channel. update_add_htlc.channel_id = chan_id_2; - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &update_add_htlc); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &update_add_htlc); check_closed_event(&nodes[2], 1, ClosureReason::ProcessingError { err: "Remote HTLC add would put them under remote reserve value".to_owned() }, false, &[nodes[1].node.get_our_node_id()], 1_000_000); @@ -4334,7 +4334,7 @@ fn test_non_strict_forwarding() { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); let mut send_event = SendEvent::from_event(msg_events.remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -4351,7 +4351,7 @@ fn test_non_strict_forwarding() { } else { channel_id_2 }); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], &send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); @@ -4372,7 +4372,7 @@ fn test_non_strict_forwarding() { let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 1); let mut send_event = SendEvent::from_event(msg_events.remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &send_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &send_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], &send_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[1]); @@ -4388,7 +4388,7 @@ fn test_non_strict_forwarding() { &[HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: routed_channel_id }]); let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false); let events = nodes[0].node.get_and_clear_pending_events(); expect_payment_failed_conditions_event(events, payment_hash, false, PaymentFailedConditions::new().blamed_scid(routed_scid)); diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 51695bba09a..5293906f91c 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -18,7 +18,7 @@ use bitcoin::constants::ChainHash; use bitcoin::secp256k1::{self, Secp256k1, SecretKey, PublicKey}; -use crate::blinded_path::message::OffersContext; +use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext}; use crate::sign::{NodeSigner, Recipient}; use crate::events::{MessageSendEvent, MessageSendEventsProvider}; use crate::ln::types::ChannelId; @@ -72,7 +72,7 @@ pub trait CustomMessageHandler: wire::CustomMessageReader { /// Handles the given message sent from `sender_node_id`, possibly producing messages for /// [`CustomMessageHandler::get_and_clear_pending_msg`] to return and thus for [`PeerManager`] /// to send. - fn handle_custom_message(&self, msg: Self::CustomMessage, sender_node_id: &PublicKey) -> Result<(), LightningError>; + fn handle_custom_message(&self, msg: Self::CustomMessage, sender_node_id: PublicKey) -> Result<(), LightningError>; /// Returns the list of pending messages that were generated by the handler, clearing the list /// in the process. Each message is paired with the node id of the intended recipient. If no @@ -80,14 +80,14 @@ pub trait CustomMessageHandler: wire::CustomMessageReader { fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)>; /// Indicates a peer disconnected. - fn peer_disconnected(&self, their_node_id: &PublicKey); + fn peer_disconnected(&self, their_node_id: PublicKey); /// Handle a peer connecting. /// /// May return an `Err(())` if the features the peer supports are not sufficient to communicate /// with us. Implementors should be somewhat conservative about doing so, however, as other /// message handlers may still wish to communicate with this peer. - fn peer_connected(&self, their_node_id: &PublicKey, msg: &Init, inbound: bool) -> Result<(), ()>; + fn peer_connected(&self, their_node_id: PublicKey, msg: &Init, inbound: bool) -> Result<(), ()>; /// Gets the node feature flags which this handler itself supports. All available handlers are /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] @@ -101,7 +101,7 @@ pub trait CustomMessageHandler: wire::CustomMessageReader { /// which are sent in our [`Init`] message. /// /// [`Init`]: crate::ln::msgs::Init - fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures; + fn provided_init_features(&self, their_node_id: PublicKey) -> InitFeatures; } /// A dummy struct which implements `RoutingMessageHandler` without storing any routing information @@ -111,32 +111,32 @@ impl MessageSendEventsProvider for IgnoringMessageHandler { fn get_and_clear_pending_msg_events(&self) -> Vec { Vec::new() } } impl RoutingMessageHandler for IgnoringMessageHandler { - fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result { Ok(false) } - fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result { Ok(false) } - fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result { Ok(false) } + fn handle_node_announcement(&self, _their_node_id: Option, _msg: &msgs::NodeAnnouncement) -> Result { Ok(false) } + fn handle_channel_announcement(&self, _their_node_id: Option, _msg: &msgs::ChannelAnnouncement) -> Result { Ok(false) } + fn handle_channel_update(&self, _their_node_id: Option, _msg: &msgs::ChannelUpdate) -> Result { Ok(false) } fn get_next_channel_announcement(&self, _starting_point: u64) -> Option<(msgs::ChannelAnnouncement, Option, Option)> { None } fn get_next_node_announcement(&self, _starting_point: Option<&NodeId>) -> Option { None } - fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } - fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), LightningError> { Ok(()) } - fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) } - fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) } - fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) } + fn peer_connected(&self, _their_node_id: PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } + fn handle_reply_channel_range(&self, _their_node_id: PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), LightningError> { Ok(()) } + fn handle_reply_short_channel_ids_end(&self, _their_node_id: PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), LightningError> { Ok(()) } + fn handle_query_channel_range(&self, _their_node_id: PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), LightningError> { Ok(()) } + fn handle_query_short_channel_ids(&self, _their_node_id: PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), LightningError> { Ok(()) } fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { InitFeatures::empty() } fn processing_queue_high(&self) -> bool { false } } impl OnionMessageHandler for IgnoringMessageHandler { - fn handle_onion_message(&self, _their_node_id: &PublicKey, _msg: &msgs::OnionMessage) {} + fn handle_onion_message(&self, _their_node_id: PublicKey, _msg: &msgs::OnionMessage) {} fn next_onion_message_for_peer(&self, _peer_node_id: PublicKey) -> Option { None } - fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } - fn peer_disconnected(&self, _their_node_id: &PublicKey) {} + fn peer_connected(&self, _their_node_id: PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } + fn peer_disconnected(&self, _their_node_id: PublicKey) {} fn timer_tick_occurred(&self) {} fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { InitFeatures::empty() } } @@ -152,7 +152,7 @@ impl AsyncPaymentsMessageHandler for IgnoringMessageHandler { ) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> { None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } impl CustomOnionMessageHandler for IgnoringMessageHandler { type CustomMessage = Infallible; @@ -202,20 +202,20 @@ impl wire::CustomMessageReader for IgnoringMessageHandler { } impl CustomMessageHandler for IgnoringMessageHandler { - fn handle_custom_message(&self, _msg: Infallible, _sender_node_id: &PublicKey) -> Result<(), LightningError> { + fn handle_custom_message(&self, _msg: Infallible, _sender_node_id: PublicKey) -> Result<(), LightningError> { // Since we always return `None` in the read the handle method should never be called. unreachable!(); } fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { Vec::new() } - fn peer_disconnected(&self, _their_node_id: &PublicKey) {} + fn peer_disconnected(&self, _their_node_id: PublicKey) {} - fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { Ok(()) } + fn peer_connected(&self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { Ok(()) } fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { InitFeatures::empty() } } @@ -230,12 +230,12 @@ impl ErroringMessageHandler { pub fn new() -> Self { Self { message_queue: Mutex::new(Vec::new()) } } - fn push_error(&self, node_id: &PublicKey, channel_id: ChannelId) { + fn push_error(&self, node_id: PublicKey, channel_id: ChannelId) { self.message_queue.lock().unwrap().push(MessageSendEvent::HandleError { action: msgs::ErrorAction::SendErrorMessage { msg: msgs::ErrorMessage { channel_id, data: "We do not support channel messages, sorry.".to_owned() }, }, - node_id: node_id.clone(), + node_id, }); } } @@ -249,76 +249,76 @@ impl MessageSendEventsProvider for ErroringMessageHandler { impl ChannelMessageHandler for ErroringMessageHandler { // Any messages which are related to a specific channel generate an error message to let the // peer know we don't care about channels. - fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannel) { + fn handle_open_channel(&self, their_node_id: PublicKey, msg: &msgs::OpenChannel) { ErroringMessageHandler::push_error(self, their_node_id, msg.common_fields.temporary_channel_id); } - fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &msgs::AcceptChannel) { + fn handle_accept_channel(&self, their_node_id: PublicKey, msg: &msgs::AcceptChannel) { ErroringMessageHandler::push_error(self, their_node_id, msg.common_fields.temporary_channel_id); } - fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &msgs::FundingCreated) { + fn handle_funding_created(&self, their_node_id: PublicKey, msg: &msgs::FundingCreated) { ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id); } - fn handle_funding_signed(&self, their_node_id: &PublicKey, msg: &msgs::FundingSigned) { + fn handle_funding_signed(&self, their_node_id: PublicKey, msg: &msgs::FundingSigned) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_channel_ready(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReady) { + fn handle_channel_ready(&self, their_node_id: PublicKey, msg: &msgs::ChannelReady) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_shutdown(&self, their_node_id: &PublicKey, msg: &msgs::Shutdown) { + fn handle_shutdown(&self, their_node_id: PublicKey, msg: &msgs::Shutdown) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &msgs::ClosingSigned) { + fn handle_closing_signed(&self, their_node_id: PublicKey, msg: &msgs::ClosingSigned) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_stfu(&self, their_node_id: &PublicKey, msg: &msgs::Stfu) { + fn handle_stfu(&self, their_node_id: PublicKey, msg: &msgs::Stfu) { ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id); } #[cfg(splicing)] - fn handle_splice_init(&self, their_node_id: &PublicKey, msg: &msgs::SpliceInit) { + fn handle_splice_init(&self, their_node_id: PublicKey, msg: &msgs::SpliceInit) { ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id); } #[cfg(splicing)] - fn handle_splice_ack(&self, their_node_id: &PublicKey, msg: &msgs::SpliceAck) { + fn handle_splice_ack(&self, their_node_id: PublicKey, msg: &msgs::SpliceAck) { ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id); } #[cfg(splicing)] - fn handle_splice_locked(&self, their_node_id: &PublicKey, msg: &msgs::SpliceLocked) { + fn handle_splice_locked(&self, their_node_id: PublicKey, msg: &msgs::SpliceLocked) { ErroringMessageHandler::push_error(&self, their_node_id, msg.channel_id); } - fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) { + fn handle_update_add_htlc(&self, their_node_id: PublicKey, msg: &msgs::UpdateAddHTLC) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) { + fn handle_update_fulfill_htlc(&self, their_node_id: PublicKey, msg: &msgs::UpdateFulfillHTLC) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) { + fn handle_update_fail_htlc(&self, their_node_id: PublicKey, msg: &msgs::UpdateFailHTLC) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_update_fail_malformed_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { + fn handle_update_fail_malformed_htlc(&self, their_node_id: PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_commitment_signed(&self, their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) { + fn handle_commitment_signed(&self, their_node_id: PublicKey, msg: &msgs::CommitmentSigned) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_revoke_and_ack(&self, their_node_id: &PublicKey, msg: &msgs::RevokeAndACK) { + fn handle_revoke_and_ack(&self, their_node_id: PublicKey, msg: &msgs::RevokeAndACK) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) { + fn handle_update_fee(&self, their_node_id: PublicKey, msg: &msgs::UpdateFee) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) { + fn handle_announcement_signatures(&self, their_node_id: PublicKey, msg: &msgs::AnnouncementSignatures) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } - fn handle_channel_reestablish(&self, their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { + fn handle_channel_reestablish(&self, their_node_id: PublicKey, msg: &msgs::ChannelReestablish) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } // msgs::ChannelUpdate does not contain the channel_id field, so we just drop them. - fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) {} - fn peer_disconnected(&self, _their_node_id: &PublicKey) {} - fn peer_connected(&self, _their_node_id: &PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } - fn handle_error(&self, _their_node_id: &PublicKey, _msg: &msgs::ErrorMessage) {} + fn handle_channel_update(&self, _their_node_id: PublicKey, _msg: &msgs::ChannelUpdate) {} + fn peer_disconnected(&self, _their_node_id: PublicKey) {} + fn peer_connected(&self, _their_node_id: PublicKey, _init: &msgs::Init, _inbound: bool) -> Result<(), ()> { Ok(()) } + fn handle_error(&self, _their_node_id: PublicKey, _msg: &msgs::ErrorMessage) {} fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { // Set a number of features which various nodes may require to talk to us. It's totally // reasonable to indicate we "support" all kinds of channel features...we just reject all // channels. @@ -345,49 +345,51 @@ impl ChannelMessageHandler for ErroringMessageHandler { None } - fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + fn handle_open_channel_v2(&self, their_node_id: PublicKey, msg: &msgs::OpenChannelV2) { ErroringMessageHandler::push_error(self, their_node_id, msg.common_fields.temporary_channel_id); } - fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) { + fn handle_accept_channel_v2(&self, their_node_id: PublicKey, msg: &msgs::AcceptChannelV2) { ErroringMessageHandler::push_error(self, their_node_id, msg.common_fields.temporary_channel_id); } - fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &msgs::TxAddInput) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + fn handle_tx_abort(&self, their_node_id: PublicKey, msg: &msgs::TxAbort) { ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id); } + + fn message_received(&self) {} } impl Deref for ErroringMessageHandler { @@ -1053,12 +1055,12 @@ impl SecretKey { let mut ephemeral_hash = self.ephemeral_key_midstate.clone(); - let counter = self.peer_counter.get_increment(); + let counter = self.peer_counter.next(); ephemeral_hash.input(&counter.to_le_bytes()); SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).to_byte_array()).expect("You broke SHA-256!") } - fn init_features(&self, their_node_id: &PublicKey) -> InitFeatures { + fn init_features(&self, their_node_id: PublicKey) -> InitFeatures { self.message_handler.chan_handler.provided_init_features(their_node_id) | self.message_handler.route_handler.provided_init_features(their_node_id) | self.message_handler.onion_message_handler.provided_init_features(their_node_id) @@ -1333,8 +1335,7 @@ impl Ok(res), Err(e) => { - log_trace!(self.logger, "Disconnecting peer due to a protocol error (usually a duplicate connection)."); - self.disconnect_event_internal(peer_descriptor); + self.disconnect_event_internal(peer_descriptor, "of a protocol error"); Err(e) } } @@ -1487,7 +1488,7 @@ impl, message: wire::Message<<::Target as wire::CustomMessageReader>::CustomMessage> ) -> Result::Target as wire::CustomMessageReader>::CustomMessage>>, MessageHandlingError> { - let their_node_id = peer_lock.their_node_id.clone().expect("We know the peer's public key by the time we receive messages").0; + let their_node_id = peer_lock.their_node_id.expect("We know the peer's public key by the time we receive messages").0; let logger = WithContext::from(&self.logger, Some(their_node_id), None, None); - let message = match self.do_handle_message_holding_peer_lock(peer_lock, message, &their_node_id, &logger)? { + self.message_handler.chan_handler.message_received(); + + let message = match self.do_handle_message_holding_peer_lock(peer_lock, message, their_node_id, &logger)? { Some(processed_message) => processed_message, None => return Ok(None), }; - self.do_handle_message_without_peer_lock(peer_mutex, message, &their_node_id, &logger) + self.do_handle_message_without_peer_lock(peer_mutex, message, their_node_id, &logger) } // Conducts all message processing that requires us to hold the `peer_lock`. @@ -1633,7 +1636,7 @@ impl, message: wire::Message<<::Target as wire::CustomMessageReader>::CustomMessage>, - their_node_id: &PublicKey, + their_node_id: PublicKey, logger: &WithContext<'a, L> ) -> Result::Target as wire::CustomMessageReader>::CustomMessage>>, MessageHandlingError> { @@ -1660,7 +1663,7 @@ impl, message: wire::Message<<::Target as wire::CustomMessageReader>::CustomMessage>, - their_node_id: &PublicKey, + their_node_id: PublicKey, logger: &WithContext<'a, L> ) -> Result::Target as wire::CustomMessageReader>::CustomMessage>>, MessageHandlingError> { @@ -1756,7 +1759,7 @@ impl { log_debug!(logger, "Got Err message from {}: {}", log_pubkey!(their_node_id), PrintableString(&msg.data)); - self.message_handler.chan_handler.handle_error(&their_node_id, &msg); + self.message_handler.chan_handler.handle_error(their_node_id, &msg); if msg.channel_id.is_zero() { return Err(PeerHandleError { }.into()); } @@ -1779,152 +1782,152 @@ impl { - self.message_handler.chan_handler.handle_open_channel(&their_node_id, &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); + 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); + 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); + 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); + self.message_handler.chan_handler.handle_funding_created(their_node_id, &msg); }, wire::Message::FundingSigned(msg) => { - self.message_handler.chan_handler.handle_funding_signed(&their_node_id, &msg); + self.message_handler.chan_handler.handle_funding_signed(their_node_id, &msg); }, wire::Message::ChannelReady(msg) => { - self.message_handler.chan_handler.handle_channel_ready(&their_node_id, &msg); + self.message_handler.chan_handler.handle_channel_ready(their_node_id, &msg); }, // Quiescence messages: wire::Message::Stfu(msg) => { - self.message_handler.chan_handler.handle_stfu(&their_node_id, &msg); + self.message_handler.chan_handler.handle_stfu(their_node_id, &msg); } #[cfg(splicing)] // Splicing messages: wire::Message::SpliceInit(msg) => { - self.message_handler.chan_handler.handle_splice_init(&their_node_id, &msg); + self.message_handler.chan_handler.handle_splice_init(their_node_id, &msg); } #[cfg(splicing)] wire::Message::SpliceAck(msg) => { - self.message_handler.chan_handler.handle_splice_ack(&their_node_id, &msg); + self.message_handler.chan_handler.handle_splice_ack(their_node_id, &msg); } #[cfg(splicing)] wire::Message::SpliceLocked(msg) => { - self.message_handler.chan_handler.handle_splice_locked(&their_node_id, &msg); + self.message_handler.chan_handler.handle_splice_locked(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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + self.message_handler.chan_handler.handle_shutdown(their_node_id, &msg); }, wire::Message::ClosingSigned(msg) => { - self.message_handler.chan_handler.handle_closing_signed(&their_node_id, &msg); + self.message_handler.chan_handler.handle_closing_signed(their_node_id, &msg); }, // Commitment messages: wire::Message::UpdateAddHTLC(msg) => { - self.message_handler.chan_handler.handle_update_add_htlc(&their_node_id, &msg); + self.message_handler.chan_handler.handle_update_add_htlc(their_node_id, &msg); }, wire::Message::UpdateFulfillHTLC(msg) => { - self.message_handler.chan_handler.handle_update_fulfill_htlc(&their_node_id, &msg); + self.message_handler.chan_handler.handle_update_fulfill_htlc(their_node_id, &msg); }, wire::Message::UpdateFailHTLC(msg) => { - self.message_handler.chan_handler.handle_update_fail_htlc(&their_node_id, &msg); + self.message_handler.chan_handler.handle_update_fail_htlc(their_node_id, &msg); }, wire::Message::UpdateFailMalformedHTLC(msg) => { - self.message_handler.chan_handler.handle_update_fail_malformed_htlc(&their_node_id, &msg); + self.message_handler.chan_handler.handle_update_fail_malformed_htlc(their_node_id, &msg); }, wire::Message::CommitmentSigned(msg) => { - self.message_handler.chan_handler.handle_commitment_signed(&their_node_id, &msg); + self.message_handler.chan_handler.handle_commitment_signed(their_node_id, &msg); }, wire::Message::RevokeAndACK(msg) => { - self.message_handler.chan_handler.handle_revoke_and_ack(&their_node_id, &msg); + self.message_handler.chan_handler.handle_revoke_and_ack(their_node_id, &msg); }, wire::Message::UpdateFee(msg) => { - self.message_handler.chan_handler.handle_update_fee(&their_node_id, &msg); + self.message_handler.chan_handler.handle_update_fee(their_node_id, &msg); }, wire::Message::ChannelReestablish(msg) => { - self.message_handler.chan_handler.handle_channel_reestablish(&their_node_id, &msg); + self.message_handler.chan_handler.handle_channel_reestablish(their_node_id, &msg); }, // Routing messages: wire::Message::AnnouncementSignatures(msg) => { - self.message_handler.chan_handler.handle_announcement_signatures(&their_node_id, &msg); + self.message_handler.chan_handler.handle_announcement_signatures(their_node_id, &msg); }, wire::Message::ChannelAnnouncement(msg) => { - if self.message_handler.route_handler.handle_channel_announcement(&msg) + if self.message_handler.route_handler.handle_channel_announcement(Some(their_node_id), &msg) .map_err(|e| -> MessageHandlingError { e.into() })? { should_forward = Some(wire::Message::ChannelAnnouncement(msg)); } self.update_gossip_backlogged(); }, wire::Message::NodeAnnouncement(msg) => { - if self.message_handler.route_handler.handle_node_announcement(&msg) + if self.message_handler.route_handler.handle_node_announcement(Some(their_node_id), &msg) .map_err(|e| -> MessageHandlingError { e.into() })? { should_forward = Some(wire::Message::NodeAnnouncement(msg)); } self.update_gossip_backlogged(); }, wire::Message::ChannelUpdate(msg) => { - self.message_handler.chan_handler.handle_channel_update(&their_node_id, &msg); - if self.message_handler.route_handler.handle_channel_update(&msg) + self.message_handler.chan_handler.handle_channel_update(their_node_id, &msg); + if self.message_handler.route_handler.handle_channel_update(Some(their_node_id), &msg) .map_err(|e| -> MessageHandlingError { e.into() })? { should_forward = Some(wire::Message::ChannelUpdate(msg)); } self.update_gossip_backlogged(); }, wire::Message::QueryShortChannelIds(msg) => { - self.message_handler.route_handler.handle_query_short_channel_ids(&their_node_id, msg)?; + self.message_handler.route_handler.handle_query_short_channel_ids(their_node_id, msg)?; }, wire::Message::ReplyShortChannelIdsEnd(msg) => { - self.message_handler.route_handler.handle_reply_short_channel_ids_end(&their_node_id, msg)?; + self.message_handler.route_handler.handle_reply_short_channel_ids_end(their_node_id, msg)?; }, wire::Message::QueryChannelRange(msg) => { - self.message_handler.route_handler.handle_query_channel_range(&their_node_id, msg)?; + self.message_handler.route_handler.handle_query_channel_range(their_node_id, msg)?; }, wire::Message::ReplyChannelRange(msg) => { - self.message_handler.route_handler.handle_reply_channel_range(&their_node_id, msg)?; + self.message_handler.route_handler.handle_reply_channel_range(their_node_id, msg)?; }, // Onion message: wire::Message::OnionMessage(msg) => { - self.message_handler.onion_message_handler.handle_onion_message(&their_node_id, &msg); + self.message_handler.onion_message_handler.handle_onion_message(their_node_id, &msg); }, // Unknown messages: @@ -1936,7 +1939,7 @@ impl { - self.message_handler.custom_message_handler.handle_custom_message(custom, &their_node_id)?; + self.message_handler.custom_message_handler.handle_custom_message(custom, their_node_id)?; }, }; Ok(should_forward) @@ -2286,13 +2289,13 @@ impl { log_debug!(self.logger, "Handling BroadcastChannelAnnouncement event in peer_handler for short channel id {}", msg.contents.short_channel_id); - match self.message_handler.route_handler.handle_channel_announcement(&msg) { + match self.message_handler.route_handler.handle_channel_announcement(None, &msg) { Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => self.forward_broadcast_msg(peers, &wire::Message::ChannelAnnouncement(msg), None), _ => {}, } if let Some(msg) = update_msg { - match self.message_handler.route_handler.handle_channel_update(&msg) { + match self.message_handler.route_handler.handle_channel_update(None, &msg) { Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None), _ => {}, @@ -2301,7 +2304,7 @@ impl { log_debug!(self.logger, "Handling BroadcastChannelUpdate event in peer_handler for contents {:?}", msg.contents); - match self.message_handler.route_handler.handle_channel_update(&msg) { + match self.message_handler.route_handler.handle_channel_update(None, &msg) { Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => self.forward_broadcast_msg(peers, &wire::Message::ChannelUpdate(msg), None), _ => {}, @@ -2309,7 +2312,7 @@ impl { log_debug!(self.logger, "Handling BroadcastNodeAnnouncement event in peer_handler for node {}", msg.contents.node_id); - match self.message_handler.route_handler.handle_node_announcement(&msg) { + match self.message_handler.route_handler.handle_node_announcement(None, &msg) { Ok(_) | Err(LightningError { action: msgs::ErrorAction::IgnoreDuplicateGossip, .. }) => self.forward_broadcast_msg(peers, &wire::Message::NodeAnnouncement(msg), None), _ => {}, @@ -2435,7 +2438,7 @@ impl { let peer = peer_lock.lock().unwrap(); if let Some((node_id, _)) = peer.their_node_id { - log_trace!(WithContext::from(&self.logger, Some(node_id), None, None), "Handling disconnection of peer {}", log_pubkey!(node_id)); + let logger = WithContext::from(&self.logger, Some(node_id), None, None); + log_trace!(logger, "Handling disconnection of peer {} because {}", log_pubkey!(node_id), reason); let removed = self.node_id_to_descriptor.lock().unwrap().remove(&node_id); debug_assert!(removed.is_some(), "descriptor maps should be consistent"); if !peer.handshake_complete() { return; } - self.message_handler.chan_handler.peer_disconnected(&node_id); - self.message_handler.onion_message_handler.peer_disconnected(&node_id); - self.message_handler.custom_message_handler.peer_disconnected(&node_id); + self.message_handler.chan_handler.peer_disconnected(node_id); + self.message_handler.onion_message_handler.peer_disconnected(node_id); + self.message_handler.custom_message_handler.peer_disconnected(node_id); } } }; @@ -2674,7 +2678,7 @@ impl Result<(), LightningError> { + fn handle_custom_message(&self, _: Infallible, _: PublicKey) -> Result<(), LightningError> { unreachable!(); } fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)> { Vec::new() } - fn peer_disconnected(&self, _their_node_id: &PublicKey) {} + fn peer_disconnected(&self, _their_node_id: PublicKey) {} - fn peer_connected(&self, _their_node_id: &PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { Ok(()) } + fn peer_connected(&self, _their_node_id: PublicKey, _msg: &Init, _inbound: bool) -> Result<(), ()> { Ok(()) } fn provided_node_features(&self) -> NodeFeatures { NodeFeatures::empty() } - fn provided_init_features(&self, _: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _: PublicKey) -> InitFeatures { self.features.clone() } } @@ -2870,8 +2874,8 @@ mod tests { }; let addr_a = SocketAddress::TcpIpV4{addr: [127, 0, 0, 1], port: 1000}; let id_b = peer_b.node_signer.get_node_id(Recipient::Node).unwrap(); - let features_a = peer_a.init_features(&id_b); - let features_b = peer_b.init_features(&id_a); + let features_a = peer_a.init_features(id_b); + let features_b = peer_b.init_features(id_a); let mut fd_b = FileDescriptor { fd: 1, outbound_data: Arc::new(Mutex::new(Vec::new())), disconnect: Arc::new(AtomicBool::new(false)), diff --git a/lightning/src/ln/priv_short_conf_tests.rs b/lightning/src/ln/priv_short_conf_tests.rs index 83ff296e177..22854952c58 100644 --- a/lightning/src/ln/priv_short_conf_tests.rs +++ b/lightning/src/ln/priv_short_conf_tests.rs @@ -24,7 +24,6 @@ use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ChannelUpdat use crate::ln::wire::Encode; use crate::util::config::{UserConfig, MaxDustHTLCExposure}; use crate::util::ser::Writeable; -use crate::util::test_utils; use crate::prelude::*; @@ -75,7 +74,7 @@ fn test_priv_forwarding_rejection() { RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0)); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false, true); let htlc_fail_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -84,15 +83,15 @@ fn test_priv_forwarding_rejection() { assert!(htlc_fail_updates.update_fail_malformed_htlcs.is_empty()); assert!(htlc_fail_updates.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_fail_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_fail_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], htlc_fail_updates.commitment_signed, true, true); expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, nodes[2].node.list_channels()[0].short_channel_id.unwrap(), true); // Now disconnect nodes[1] from its peers and restart with accept_forwards_to_priv_channels set // to true. Sadly there is currently no way to change it at runtime. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); let nodes_1_serialized = nodes[1].node.encode(); let monitor_a_serialized = get_monitor!(nodes[1], chan_id_1).encode(); @@ -101,29 +100,29 @@ fn test_priv_forwarding_rejection() { no_announce_cfg.accept_forwards_to_priv_channels = true; reload_node!(nodes[1], no_announce_cfg, &nodes_1_serialized, &[&monitor_a_serialized, &monitor_b_serialized], persister, new_chain_monitor, nodes_1_deserialized); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let as_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id()); - nodes[1].node.peer_connected(&nodes[2].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[2].node.get_our_node_id(), &msgs::Init { features: nodes[2].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[2].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[2].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[2]).pop().unwrap(); let cs_reestablish = get_chan_reestablish_msgs!(nodes[2], nodes[1]).pop().unwrap(); - nodes[2].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); - nodes[1].node.handle_channel_reestablish(&nodes[2].node.get_our_node_id(), &cs_reestablish); + nodes[2].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[2].node.get_our_node_id(), &cs_reestablish); get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[2].node.get_our_node_id()); get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); @@ -155,7 +154,7 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001); mine_transaction(&nodes[1], &tx); - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id())); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[0].node.get_our_node_id())); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); mine_transaction(&nodes[0], &tx); @@ -169,7 +168,7 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { assert_eq!(*node_id, nodes[1].node.get_our_node_id()); } else { panic!("Unexpected event"); } - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); expect_channel_ready_event(&nodes[0], &nodes[1].node.get_our_node_id()); expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id()); let bs_msg_events = nodes[1].node.get_and_clear_pending_msg_events(); @@ -185,7 +184,7 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { connect_blocks(&nodes[0], 4); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); connect_blocks(&nodes[0], 1); - nodes[1].node.handle_announcement_signatures(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendAnnouncementSignatures, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_announcement_signatures(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendAnnouncementSignatures, nodes[1].node.get_our_node_id())); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); connect_blocks(&nodes[1], 5); @@ -199,7 +198,7 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { (msg.clone(), update_msg.clone().unwrap()) } else { panic!("Unexpected event"); }; - nodes[0].node.handle_announcement_signatures(&nodes[1].node.get_our_node_id(), &bs_announcement_sigs); + nodes[0].node.handle_announcement_signatures(nodes[1].node.get_our_node_id(), &bs_announcement_sigs); let as_announce_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(as_announce_events.len(), 1); let (announcement, as_update) = if let MessageSendEvent::BroadcastChannelAnnouncement { ref msg, ref update_msg } = as_announce_events[0] { @@ -207,10 +206,11 @@ fn do_test_1_conf_open(connect_style: ConnectStyle) { } else { panic!("Unexpected event"); }; assert_eq!(announcement, bs_announcement); - for node in nodes { - assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); - node.gossip_sync.handle_channel_update(&as_update).unwrap(); - node.gossip_sync.handle_channel_update(&bs_update).unwrap(); + for (i, node) in nodes.iter().enumerate() { + let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id(); + assert!(node.gossip_sync.handle_channel_announcement(Some(counterparty_node_id), &announcement).unwrap()); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &as_update).unwrap(); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &bs_update).unwrap(); } } #[test] @@ -257,7 +257,7 @@ fn test_routed_scid_alias() { pass_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], 100_000, payment_hash, payment_secret); as_channel_ready.short_channel_id_alias = Some(0xeadbeef); - nodes[2].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &as_channel_ready); + nodes[2].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &as_channel_ready); // Note that we always respond to a channel_ready with a channel_update. Not a lot of reason // to bother updating that code, so just drop the message here. get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); @@ -267,7 +267,7 @@ fn test_routed_scid_alias() { // Now test that if a peer sends us a second channel_ready after the channel is operational we // will use the new alias. as_channel_ready.short_channel_id_alias = Some(0xdeadbeef); - nodes[2].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &as_channel_ready); + nodes[2].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &as_channel_ready); // Note that we always respond to a channel_ready with a channel_update. Not a lot of reason // to bother updating that code, so just drop the message here. get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); @@ -297,7 +297,7 @@ fn test_scid_privacy_on_pub_channel() { open_channel.common_fields.channel_type.as_mut().unwrap().set_scid_privacy_required(); assert_eq!(open_channel.common_fields.channel_flags & 1, 1); // The `announce_channel` bit is set. - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let err = get_err_msg(&nodes[1], &nodes[0].node.get_our_node_id()); assert_eq!(err.data, "SCID Alias/Privacy Channel Type cannot be set on a public channel"); } @@ -322,7 +322,7 @@ fn test_scid_privacy_negotiation() { // now simulate nodes[1] responding with an Error message, indicating it doesn't understand // SCID alias. - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &msgs::ErrorMessage { channel_id: init_open_channel.common_fields.temporary_channel_id, data: "Yo, no SCID aliases, no privacy here!".to_string() }); @@ -330,8 +330,8 @@ fn test_scid_privacy_negotiation() { let second_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); assert!(!second_open_channel.common_fields.channel_type.as_ref().unwrap().supports_scid_privacy()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &second_open_channel); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &second_open_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id())); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -365,19 +365,19 @@ fn test_inbound_scid_privacy() { assert!(open_channel.common_fields.channel_type.as_ref().unwrap().requires_scid_privacy()); - nodes[2].node.handle_open_channel(&nodes[1].node.get_our_node_id(), &open_channel); + nodes[2].node.handle_open_channel(nodes[1].node.get_our_node_id(), &open_channel); let accept_channel = get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_accept_channel(&nodes[2].node.get_our_node_id(), &accept_channel); + nodes[1].node.handle_accept_channel(nodes[2].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42); nodes[1].node.funding_transaction_generated(temporary_channel_id, nodes[2].node.get_our_node_id(), tx.clone()).unwrap(); - nodes[2].node.handle_funding_created(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingCreated, nodes[2].node.get_our_node_id())); + nodes[2].node.handle_funding_created(nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingCreated, nodes[2].node.get_our_node_id())); check_added_monitors!(nodes[2], 1); let cs_funding_signed = get_event_msg!(nodes[2], MessageSendEvent::SendFundingSigned, nodes[1].node.get_our_node_id()); expect_channel_pending_event(&nodes[2], &nodes[1].node.get_our_node_id()); - nodes[1].node.handle_funding_signed(&nodes[2].node.get_our_node_id(), &cs_funding_signed); + nodes[1].node.handle_funding_signed(nodes[2].node.get_our_node_id(), &cs_funding_signed); expect_channel_pending_event(&nodes[1], &nodes[2].node.get_our_node_id()); check_added_monitors!(nodes[1], 1); @@ -387,15 +387,15 @@ fn test_inbound_scid_privacy() { confirm_transaction_at(&nodes[2], &tx, conf_height); connect_blocks(&nodes[2], CHAN_CONFIRM_DEPTH - 1); let bs_channel_ready = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, nodes[2].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[2].node.get_our_node_id(), &get_event_msg!(nodes[2], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_channel_ready(nodes[2].node.get_our_node_id(), &get_event_msg!(nodes[2], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id())); expect_channel_ready_event(&nodes[1], &nodes[2].node.get_our_node_id()); let bs_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[2].node.get_our_node_id()); - nodes[2].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &bs_channel_ready); + nodes[2].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &bs_channel_ready); expect_channel_ready_event(&nodes[2], &nodes[1].node.get_our_node_id()); let cs_update = get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &cs_update); - nodes[2].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &bs_update); + nodes[1].node.handle_channel_update(nodes[2].node.get_our_node_id(), &cs_update); + nodes[2].node.handle_channel_update(nodes[1].node.get_our_node_id(), &bs_update); // Now we can pay just fine using the SCID alias nodes[2] gave to nodes[1]... @@ -438,13 +438,13 @@ fn test_inbound_scid_privacy() { let payment_event = SendEvent::from_node(&nodes[0]); assert_eq!(nodes[1].node.get_our_node_id(), payment_event.node_id); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, true, true); nodes[1].logger.assert_log_regex("lightning::ln::channelmanager", regex::Regex::new(r"Refusing to forward over real channel SCID as our counterparty requested").unwrap(), 1); let mut updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false); expect_payment_failed_conditions(&nodes[0], payment_hash_2, false, @@ -492,7 +492,7 @@ fn test_scid_alias_returned() { RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], &as_updates.commitment_signed, false, true); expect_pending_htlcs_forwardable!(nodes[1]); @@ -500,7 +500,7 @@ fn test_scid_alias_returned() { check_added_monitors!(nodes[1], 1); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false, true); // Build the expected channel update @@ -537,11 +537,11 @@ fn test_scid_alias_returned() { RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let as_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_updates.update_add_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[0], &as_updates.commitment_signed, false, true); let bs_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &bs_updates.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false, true); let mut err_data = Vec::new(); @@ -595,7 +595,7 @@ fn test_0conf_channel_with_async_monitor() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, Some(chan_config)).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { @@ -607,14 +607,14 @@ fn test_0conf_channel_with_async_monitor() { let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); assert_eq!(accept_channel.common_fields.minimum_depth, 0); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); nodes[0].node.funding_transaction_generated(temporary_channel_id, nodes[1].node.get_our_node_id(), tx.clone()).unwrap(); let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); @@ -629,7 +629,7 @@ fn test_0conf_channel_with_async_monitor() { match &bs_signed_locked[0] { MessageSendEvent::SendFundingSigned { node_id, msg } => { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &msg); check_added_monitors!(nodes[0], 1); } _ => panic!("Unexpected event"), @@ -637,7 +637,7 @@ fn test_0conf_channel_with_async_monitor() { match &bs_signed_locked[1] { MessageSendEvent::SendChannelReady { node_id, msg } => { assert_eq!(*node_id, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &msg); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &msg); } _ => panic!("Unexpected event"), } @@ -672,7 +672,7 @@ fn test_0conf_channel_with_async_monitor() { match &as_locked_update[0] { MessageSendEvent::SendChannelReady { node_id, msg } => { assert_eq!(*node_id, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &msg); } _ => panic!("Unexpected event"), } @@ -691,8 +691,8 @@ fn test_0conf_channel_with_async_monitor() { chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); - nodes[0].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &bs_channel_update); - nodes[1].node.handle_channel_update(&nodes[0].node.get_our_node_id(), &as_channel_update); + nodes[0].node.handle_channel_update(nodes[1].node.get_our_node_id(), &bs_channel_update); + nodes[1].node.handle_channel_update(nodes[0].node.get_our_node_id(), &as_channel_update); assert_eq!(nodes[0].node.list_usable_channels().len(), 1); assert_eq!(nodes[1].node.list_usable_channels().len(), 2); @@ -708,19 +708,19 @@ fn test_0conf_channel_with_async_monitor() { check_added_monitors!(nodes[0], 1); let as_send = SendEvent::from_node(&nodes[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &as_send.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_send.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &as_send.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &as_send.commitment_msg); check_added_monitors!(nodes[1], 1); let (bs_raa, bs_commitment_signed) = get_revoke_commit_msgs!(nodes[1], nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors!(nodes[0], 1); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_commitment_signed); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_commitment_signed); check_added_monitors!(nodes[0], 1); chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id())); check_added_monitors!(nodes[1], 1); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -732,7 +732,7 @@ fn test_0conf_channel_with_async_monitor() { check_added_monitors!(nodes[1], 1); let bs_send = SendEvent::from_node(&nodes[1]); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &bs_send.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &bs_send.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], bs_send.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); expect_payment_claimable!(nodes[2], payment_hash, payment_secret, 1_000_000); @@ -793,8 +793,8 @@ fn test_public_0conf_channel() { assert_eq!(confirm_transaction(&nodes[1], &tx), scid); let bs_announcement_sigs = get_event_msg!(nodes[1], MessageSendEvent::SendAnnouncementSignatures, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_announcement_signatures(&nodes[0].node.get_our_node_id(), &as_announcement_sigs); - nodes[0].node.handle_announcement_signatures(&nodes[1].node.get_our_node_id(), &bs_announcement_sigs); + nodes[1].node.handle_announcement_signatures(nodes[0].node.get_our_node_id(), &as_announcement_sigs); + nodes[0].node.handle_announcement_signatures(nodes[1].node.get_our_node_id(), &bs_announcement_sigs); let bs_announcement = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(bs_announcement.len(), 1); @@ -889,7 +889,7 @@ fn test_zero_conf_accept_reject() { open_channel_msg.common_fields.channel_type = Some(channel_type_features.clone()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let msg_events = nodes[1].node.get_and_clear_pending_msg_events(); match msg_events[0] { @@ -917,7 +917,7 @@ fn test_zero_conf_accept_reject() { open_channel_msg.common_fields.channel_type = Some(channel_type_features.clone()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in the `msg_events`. assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -949,7 +949,7 @@ fn test_zero_conf_accept_reject() { open_channel_msg.common_fields.channel_type = Some(channel_type_features); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel_msg); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel_msg); let events = nodes[1].node.get_and_clear_pending_events(); @@ -987,7 +987,7 @@ fn test_connect_before_funding() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100_000, 10_001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let events = nodes[1].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { @@ -999,7 +999,7 @@ fn test_connect_before_funding() { let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); assert_eq!(accept_channel.common_fields.minimum_depth, 0); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); @@ -1037,12 +1037,12 @@ fn test_0conf_ann_sigs_racing_conf() { let as_announcement_sigs = get_event_msg!(nodes[0], MessageSendEvent::SendAnnouncementSignatures, nodes[1].node.get_our_node_id()); // Handling the announcement_signatures prior to the first confirmation would panic before. - nodes[1].node.handle_announcement_signatures(&nodes[0].node.get_our_node_id(), &as_announcement_sigs); + nodes[1].node.handle_announcement_signatures(nodes[0].node.get_our_node_id(), &as_announcement_sigs); assert_eq!(confirm_transaction(&nodes[1], &tx), scid); let bs_announcement_sigs = get_event_msg!(nodes[1], MessageSendEvent::SendAnnouncementSignatures, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_announcement_signatures(&nodes[1].node.get_our_node_id(), &bs_announcement_sigs); + nodes[0].node.handle_announcement_signatures(nodes[1].node.get_our_node_id(), &bs_announcement_sigs); let as_announcement = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(as_announcement.len(), 1); } diff --git a/lightning/src/ln/reload_tests.rs b/lightning/src/ln/reload_tests.rs index a17f8495a9a..129b83eae71 100644 --- a/lightning/src/ln/reload_tests.rs +++ b/lightning/src/ln/reload_tests.rs @@ -44,8 +44,8 @@ fn test_funding_peer_disconnect() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); confirm_transaction(&nodes[0], &tx); let events_1 = nodes[0].node.get_and_clear_pending_msg_events(); @@ -55,24 +55,24 @@ fn test_funding_peer_disconnect() { reconnect_args.send_channel_ready.1 = true; reconnect_nodes(reconnect_args); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); confirm_transaction(&nodes[1], &tx); let events_2 = nodes[1].node.get_and_clear_pending_msg_events(); assert!(events_2.is_empty()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let as_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let bs_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); // nodes[0] hasn't yet received a channel_ready, so it only sends that on reconnect. - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &bs_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &bs_reestablish); let events_3 = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events_3.len(), 1); let as_channel_ready = match events_3[0] { @@ -85,7 +85,7 @@ fn test_funding_peer_disconnect() { // nodes[1] received nodes[0]'s channel_ready on the first reconnect above, so it should send // announcement_signatures as well as channel_update. - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &as_reestablish); let events_4 = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events_4.len(), 3); let chan_id; @@ -113,7 +113,7 @@ fn test_funding_peer_disconnect() { // Re-deliver nodes[0]'s channel_ready, which nodes[1] can safely ignore. It currently // generates a duplicative private channel_update - nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &as_channel_ready); + nodes[1].node.handle_channel_ready(nodes[0].node.get_our_node_id(), &as_channel_ready); let events_5 = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events_5.len(), 1); match events_5[0] { @@ -125,7 +125,7 @@ fn test_funding_peer_disconnect() { // When we deliver nodes[1]'s channel_ready, however, nodes[0] will generate its // announcement_signatures. - nodes[0].node.handle_channel_ready(&nodes[1].node.get_our_node_id(), &bs_channel_ready); + nodes[0].node.handle_channel_ready(nodes[1].node.get_our_node_id(), &bs_channel_ready); let events_6 = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events_6.len(), 1); let as_announcement_sigs = match events_6[0] { @@ -141,7 +141,7 @@ fn test_funding_peer_disconnect() { // When we deliver nodes[1]'s announcement_signatures to nodes[0], nodes[0] should immediately // broadcast the channel announcement globally, as well as re-send its (now-public) // channel_update. - nodes[0].node.handle_announcement_signatures(&nodes[1].node.get_our_node_id(), &bs_announcement_sigs); + nodes[0].node.handle_announcement_signatures(nodes[1].node.get_our_node_id(), &bs_announcement_sigs); let events_7 = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events_7.len(), 1); let (chan_announcement, as_update) = match events_7[0] { @@ -153,7 +153,7 @@ fn test_funding_peer_disconnect() { // Finally, deliver nodes[0]'s announcement_signatures to nodes[1] and make sure it creates the // same channel_announcement. - nodes[1].node.handle_announcement_signatures(&nodes[0].node.get_our_node_id(), &as_announcement_sigs); + nodes[1].node.handle_announcement_signatures(nodes[0].node.get_our_node_id(), &as_announcement_sigs); let events_8 = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events_8.len(), 1); let bs_update = match events_8[0] { @@ -165,9 +165,10 @@ fn test_funding_peer_disconnect() { }; // Provide the channel announcement and public updates to the network graph - nodes[0].gossip_sync.handle_channel_announcement(&chan_announcement).unwrap(); - nodes[0].gossip_sync.handle_channel_update(&bs_update).unwrap(); - nodes[0].gossip_sync.handle_channel_update(&as_update).unwrap(); + let node_1_pubkey = nodes[1].node.get_our_node_id(); + nodes[0].gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &chan_announcement).unwrap(); + nodes[0].gossip_sync.handle_channel_update(Some(node_1_pubkey), &bs_update).unwrap(); + nodes[0].gossip_sync.handle_channel_update(Some(node_1_pubkey), &as_update).unwrap(); let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000); let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0; @@ -175,7 +176,7 @@ fn test_funding_peer_disconnect() { // Check that after deserialization and reconnection we can still generate an identical // channel_announcement from the cached signatures. - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode(); @@ -197,32 +198,33 @@ fn test_no_txn_manager_serialize_deserialize() { let tx = create_chan_between_nodes_with_value_init(&nodes[0], &nodes[1], 100000, 10001); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let chan_0_monitor_serialized = get_monitor!(nodes[0], ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 0 })).encode(); reload_node!(nodes[0], nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx); let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready); - for node in nodes.iter() { - assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); - node.gossip_sync.handle_channel_update(&as_update).unwrap(); - node.gossip_sync.handle_channel_update(&bs_update).unwrap(); + for (i, node) in nodes.iter().enumerate() { + let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id(); + assert!(node.gossip_sync.handle_channel_announcement(Some(counterparty_node_id), &announcement).unwrap()); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &as_update).unwrap(); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &bs_update).unwrap(); } send_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -246,15 +248,15 @@ fn test_manager_serialize_deserialize_events() { let node_a = nodes.remove(0); let node_b = nodes.remove(0); node_a.node.create_channel(node_b.node.get_our_node_id(), channel_value, push_msat, 42, None, None).unwrap(); - node_b.node.handle_open_channel(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id())); - node_a.node.handle_accept_channel(&node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id())); + node_b.node.handle_open_channel(node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id())); + node_a.node.handle_accept_channel(node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id())); let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42); node_a.node.funding_transaction_generated(temporary_channel_id, node_b.node.get_our_node_id(), tx.clone()).unwrap(); check_added_monitors!(node_a, 0); - node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id())); + node_b.node.handle_funding_created(node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id())); { let mut added_monitors = node_b.chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -263,7 +265,7 @@ fn test_manager_serialize_deserialize_events() { } let bs_funding_signed = get_event_msg!(node_b, MessageSendEvent::SendFundingSigned, node_a.node.get_our_node_id()); - node_a.node.handle_funding_signed(&node_b.node.get_our_node_id(), &bs_funding_signed); + node_a.node.handle_funding_signed(node_b.node.get_our_node_id(), &bs_funding_signed); { let mut added_monitors = node_a.chain_monitor.added_monitors.lock().unwrap(); assert_eq!(added_monitors.len(), 1); @@ -282,7 +284,7 @@ fn test_manager_serialize_deserialize_events() { let chan_0_monitor_serialized = get_monitor!(nodes[0], bs_funding_signed.channel_id).encode(); reload_node!(nodes[0], nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); // After deserializing, make sure the funding_transaction is still held by the channel manager let events_4 = nodes[0].node.get_and_clear_pending_events(); @@ -293,26 +295,27 @@ fn test_manager_serialize_deserialize_events() { // Make sure the channel is functioning as though the de/serialization never happened assert_eq!(nodes[0].node.list_channels().len(), 1); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_2[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); let (channel_ready, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx); let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &channel_ready); - for node in nodes.iter() { - assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap()); - node.gossip_sync.handle_channel_update(&as_update).unwrap(); - node.gossip_sync.handle_channel_update(&bs_update).unwrap(); + for (i, node) in nodes.iter().enumerate() { + let counterparty_node_id = nodes[(i + 1) % 2].node.get_our_node_id(); + assert!(node.gossip_sync.handle_channel_announcement(Some(counterparty_node_id), &announcement).unwrap()); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &as_update).unwrap(); + node.gossip_sync.handle_channel_update(Some(counterparty_node_id), &bs_update).unwrap(); } send_payment(&nodes[0], &[&nodes[1]], 1000000); @@ -333,7 +336,7 @@ fn test_simple_manager_serialize_deserialize() { let (our_payment_preimage, ..) = route_payment(&nodes[0], &[&nodes[1]], 1000000); let (_, our_payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 1000000); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode(); reload_node!(nodes[0], nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized); @@ -375,9 +378,9 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { let nodes_0_serialized = nodes[0].node.encode(); route_payment(&nodes[0], &[&nodes[3]], 1000000); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[0].node.get_our_node_id()); - nodes[3].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[0].node.get_our_node_id()); + nodes[3].node.peer_disconnected(nodes[0].node.get_our_node_id()); // Now the ChannelMonitor (which is now out-of-sync with ChannelManager for channel w/ // nodes[3]) @@ -468,14 +471,14 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() { //... and we can even still claim the payment! claim_payment(&nodes[2], &[&nodes[0], &nodes[1]], our_payment_preimage); - nodes[3].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[3].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish = get_chan_reestablish_msgs!(nodes[3], nodes[0]).pop().unwrap(); - nodes[0].node.peer_connected(&nodes[3].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[3].node.get_our_node_id(), &msgs::Init { features: nodes[3].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[3].node.get_our_node_id(), &reestablish); + nodes[0].node.handle_channel_reestablish(nodes[3].node.get_our_node_id(), &reestablish); let mut found_err = false; for msg_event in nodes[0].node.get_and_clear_pending_msg_events() { if let MessageSendEvent::HandleError { ref action, .. } = msg_event { @@ -531,20 +534,20 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, check_added_monitors(&nodes[0], 1); let update_add_commit = SendEvent::from_node(&nodes[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &update_add_commit.msgs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &update_add_commit.commitment_msg); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &update_add_commit.msgs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &update_add_commit.commitment_msg); check_added_monitors(&nodes[1], 1); let (raa, cs) = get_revoke_commit_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &raa); check_added_monitors(&nodes[0], 1); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); if !not_stale { - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &cs); check_added_monitors(&nodes[0], 1); // A now revokes their original state, at which point reconnect should panic let raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &raa); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &raa); check_added_monitors(&nodes[1], 1); expect_pending_htlcs_forwardable_ignore!(nodes[1]); } @@ -553,16 +556,16 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, send_payment(&nodes[0], &[&nodes[1]], 8000000); } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); reload_node!(nodes[0], previous_node_state, &[&previous_chain_monitor_state], persister, new_chain_monitor, nodes_0_deserialized); if reconnect_panicing { - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); @@ -570,7 +573,7 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, // If A has fallen behind substantially, B should send it a message letting it know // that. - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &reestablish_1[0]); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]); let reestablish_msg; if substantially_old { let warn_msg = "Peer attempted to reestablish channel with a very old local commitment transaction: 0 (received) vs 4 (expected)".to_owned(); @@ -610,7 +613,7 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, // Check A panics upon seeing proof it has fallen behind. let reconnect_res = std::panic::catch_unwind(|| { - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &reestablish_msg); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_msg); }); if not_stale { assert!(reconnect_res.is_ok()); @@ -655,15 +658,15 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, // after the warning message sent by B, we should not able to // use the channel, or reconnect with success to the channel. assert!(nodes[0].node.list_usable_channels().is_empty()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let retry_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &retry_reestablish[0]); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &retry_reestablish[0]); let mut err_msgs_0 = Vec::with_capacity(1); if let MessageSendEvent::HandleError { ref action, .. } = nodes[0].node.get_and_clear_pending_msg_events()[1] { match action { @@ -677,7 +680,7 @@ fn do_test_data_loss_protect(reconnect_panicing: bool, substantially_old: bool, panic!("Unexpected event!"); } assert_eq!(err_msgs_0.len(), 1); - nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), &err_msgs_0[0]); + nodes[1].node.handle_error(nodes[0].node.get_our_node_id(), &err_msgs_0[0]); assert!(nodes[1].node.list_usable_channels().is_empty()); check_added_monitors!(nodes[1], 1); check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyForceClosed { peer_msg: UntrustedString(format!("Got a message for a channel from the wrong node! No such channel for the passed counterparty_node_id {}", &nodes[1].node.get_our_node_id())) } @@ -722,7 +725,7 @@ fn test_forwardable_regen() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable_ignore!(nodes[1]); @@ -736,7 +739,7 @@ fn test_forwardable_regen() { let mut events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // There is already a PendingHTLCsForwardable event "pending" so another one will not be @@ -744,8 +747,8 @@ fn test_forwardable_regen() { assert!(nodes[1].node.get_and_clear_pending_events().is_empty()); // Now restart nodes[1] and make sure it regenerates a single PendingHTLCsForwardable - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[1].node.get_our_node_id()); let chan_0_monitor_serialized = get_monitor!(nodes[1], chan_id_1).encode(); let chan_1_monitor_serialized = get_monitor!(nodes[1], chan_id_2).encode(); @@ -767,7 +770,7 @@ fn test_forwardable_regen() { let mut events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); let payment_event = SendEvent::from_event(events.pop().unwrap()); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[2], nodes[1], payment_event.commitment_msg, false); expect_pending_htlcs_forwardable!(nodes[2]); expect_payment_claimable!(nodes[2], payment_hash_2, payment_secret_2, 200_000); @@ -877,8 +880,8 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) { assert!(get_monitor!(nodes[3], chan_id_persisted).get_stored_preimages().contains_key(&payment_hash)); assert!(get_monitor!(nodes[3], chan_id_not_persisted).get_stored_preimages().contains_key(&payment_hash)); - nodes[1].node.peer_disconnected(&nodes[3].node.get_our_node_id()); - nodes[2].node.peer_disconnected(&nodes[3].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[3].node.get_our_node_id()); + nodes[2].node.peer_disconnected(nodes[3].node.get_our_node_id()); // During deserialization, we should have closed one channel and broadcast its latest // commitment transaction. We should also still have the original PaymentClaimable event we @@ -906,20 +909,20 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) { if !persist_both_monitors { // If one of the two channels is still live, reveal the payment preimage over it. - nodes[3].node.peer_connected(&nodes[2].node.get_our_node_id(), &msgs::Init { + nodes[3].node.peer_connected(nodes[2].node.get_our_node_id(), &msgs::Init { features: nodes[2].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let reestablish_1 = get_chan_reestablish_msgs!(nodes[3], nodes[2]); - nodes[2].node.peer_connected(&nodes[3].node.get_our_node_id(), &msgs::Init { + nodes[2].node.peer_connected(nodes[3].node.get_our_node_id(), &msgs::Init { features: nodes[3].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let reestablish_2 = get_chan_reestablish_msgs!(nodes[2], nodes[3]); - nodes[2].node.handle_channel_reestablish(&nodes[3].node.get_our_node_id(), &reestablish_1[0]); + nodes[2].node.handle_channel_reestablish(nodes[3].node.get_our_node_id(), &reestablish_1[0]); get_event_msg!(nodes[2], MessageSendEvent::SendChannelUpdate, nodes[3].node.get_our_node_id()); assert!(nodes[2].node.get_and_clear_pending_msg_events().is_empty()); - nodes[3].node.handle_channel_reestablish(&nodes[2].node.get_our_node_id(), &reestablish_2[0]); + nodes[3].node.handle_channel_reestablish(nodes[2].node.get_our_node_id(), &reestablish_2[0]); // Once we call `get_and_clear_pending_msg_events` the holding cell is cleared and the HTLC // claim should fly. @@ -930,7 +933,7 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) { let cs_updates = match ds_msgs[1] { MessageSendEvent::UpdateHTLCs { ref updates, .. } => { - nodes[2].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[2].node.handle_update_fulfill_htlc(nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); check_added_monitors!(nodes[2], 1); let cs_updates = get_htlc_update_msgs!(nodes[2], nodes[0].node.get_our_node_id()); expect_payment_forwarded!(nodes[2], nodes[0], nodes[3], Some(1000), false, false); @@ -940,7 +943,7 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) { _ => panic!(), }; - nodes[0].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &cs_updates.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[2], cs_updates.commitment_signed, false, true); expect_payment_sent!(nodes[0], payment_preimage); } @@ -987,7 +990,7 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht check_added_monitors!(nodes[0], 1); let payment_event = SendEvent::from_node(&nodes[0]); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false); // Store the `ChannelManager` before handling the `PendingHTLCsForwardable`/`HTLCIntercepted` @@ -1014,8 +1017,8 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht expect_pending_htlcs_forwardable!(nodes[1]); let payment_event = SendEvent::from_node(&nodes[1]); - nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); - nodes[2].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); + nodes[2].node.handle_update_add_htlc(nodes[1].node.get_our_node_id(), &payment_event.msgs[0]); + nodes[2].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &payment_event.commitment_msg); check_added_monitors!(nodes[2], 1); if claim_htlc { @@ -1058,7 +1061,7 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht assert_eq!(bs_commitment_tx.len(), 1); check_added_monitors!(nodes[1], 1); - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); if use_cs_commitment { @@ -1093,9 +1096,9 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht match &events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { update_fulfill_htlcs, update_fail_htlcs, commitment_signed, .. }, .. } => { if claim_htlc { - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &update_fulfill_htlcs[0]); } else { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); } commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false); }, @@ -1154,7 +1157,7 @@ fn removed_payment_no_manager_persistence() { assert_eq!(events.len(), 1); match &events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { update_fail_htlcs, commitment_signed, .. }, .. } => { - nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[2].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[1], nodes[2], commitment_signed, false); }, _ => panic!("Unexpected event"), @@ -1177,7 +1180,7 @@ fn removed_payment_no_manager_persistence() { // Now that the ChannelManager has force-closed the channel which had the HTLC removed, it is // now forgotten everywhere. The ChannelManager should have, as a side-effect of reload, // learned that the HTLC is gone from the ChannelMonitor and added it to the to-fail-back set. - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1])); expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], [HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_id_2 }]); @@ -1186,7 +1189,7 @@ fn removed_payment_no_manager_persistence() { assert_eq!(events.len(), 1); match &events[0] { MessageSendEvent::UpdateHTLCs { updates: msgs::CommitmentUpdate { update_fail_htlcs, commitment_signed, .. }, .. } => { - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], commitment_signed, false); }, _ => panic!("Unexpected event"), @@ -1213,13 +1216,13 @@ fn test_reload_partial_funding_batch() { ]); // Go through the funding_created and funding_signed flow with node 1. - nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); + nodes[1].node.handle_funding_created(nodes[0].node.get_our_node_id(), &funding_created_msgs[0]); check_added_monitors(&nodes[1], 1); expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id()); // The monitor is persisted when receiving funding_signed. let funding_signed_msg = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed_msg); + nodes[0].node.handle_funding_signed(nodes[1].node.get_our_node_id(), &funding_signed_msg); check_added_monitors(&nodes[0], 1); // The transaction should not have been broadcast before all channels are ready. diff --git a/lightning/src/ln/reorg_tests.rs b/lightning/src/ln/reorg_tests.rs index 4fa740e0271..5d4f1540fb9 100644 --- a/lightning/src/ln/reorg_tests.rs +++ b/lightning/src/ln/reorg_tests.rs @@ -17,7 +17,6 @@ use crate::events::{Event, MessageSendEventsProvider, ClosureReason, HTLCDestina use crate::ln::msgs::{ChannelMessageHandler, Init}; use crate::ln::types::ChannelId; use crate::sign::OutputSpender; -use crate::util::test_utils; use crate::util::ser::Writeable; use crate::util::string::UntrustedString; @@ -139,10 +138,10 @@ fn do_test_onchain_htlc_reorg(local_commitment: bool, claim: bool) { let htlc_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); if claim { assert_eq!(htlc_updates.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &htlc_updates.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &htlc_updates.update_fulfill_htlcs[0]); } else { assert_eq!(htlc_updates.update_fail_htlcs.len(), 1); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &htlc_updates.update_fail_htlcs[0]); } commitment_signed_dance!(nodes[0], nodes[1], htlc_updates.commitment_signed, false, true); if claim { @@ -370,7 +369,7 @@ fn do_test_unconf_chan(reload_node: bool, reorg_after_reload: bool, use_funding_ // If we dropped the channel before reloading the node, nodes[1] was also dropped from // nodes[0] storage, and hence not connected again on startup. We therefore need to // reconnect to the node before attempting to create a new channel. - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); } @@ -719,7 +718,7 @@ fn test_htlc_preimage_claim_prev_counterparty_commitment_after_current_counterpa // Handle the fee update on the other side, but don't send the last RAA such that the previous // commitment is still valid (unrevoked). - nodes[1].node().handle_update_fee(&nodes[0].node.get_our_node_id(), &update_fee); + nodes[1].node().handle_update_fee(nodes[0].node.get_our_node_id(), &update_fee); let _last_revoke_and_ack = commitment_signed_dance!(nodes[1], nodes[0], commit_sig, false, true, false, true); let error_message = "Channel force-closed"; @@ -800,7 +799,7 @@ fn do_test_retries_own_commitment_broadcast_after_reorg(anchors: bool, revoked_c check_added_monitors!(nodes[0], 1); let fee_update = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &fee_update.update_fee.unwrap()); commitment_signed_dance!(nodes[1], nodes[0], fee_update.commitment_signed, false); reload_node!( diff --git a/lightning/src/ln/shutdown_tests.rs b/lightning/src/ln/shutdown_tests.rs index 3a92f02ccb5..9fd428329af 100644 --- a/lightning/src/ln/shutdown_tests.rs +++ b/lightning/src/ln/shutdown_tests.rs @@ -52,16 +52,16 @@ fn pre_funding_lock_shutdown_test() { nodes[0].node.close_channel(&ChannelId::v1_from_funding_outpoint(OutPoint { txid: tx.compute_txid(), index: 0 }), &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); @@ -88,7 +88,7 @@ fn expect_channel_shutdown_state() { expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NotShuttingDown); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); // node1 goes into NegotiatingClosingFee since there are no HTLCs in flight, note that it // doesnt mean that node1 has sent/recved its closing signed message @@ -96,17 +96,17 @@ fn expect_channel_shutdown_state() { expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NegotiatingClosingFee); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); @@ -137,13 +137,13 @@ fn expect_channel_shutdown_state_with_htlc() { expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::NotShuttingDown); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::ShutdownInitiated); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::ResolvingHTLCs); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); expect_channel_shutdown_state!(nodes[0], chan_1.2, ChannelShutdownState::ResolvingHTLCs); expect_channel_shutdown_state!(nodes[1], chan_1.2, ChannelShutdownState::ResolvingHTLCs); @@ -163,7 +163,7 @@ fn expect_channel_shutdown_state_with_htlc() { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); check_added_monitors!(nodes[1], 1); let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -178,7 +178,7 @@ fn expect_channel_shutdown_state_with_htlc() { assert!(updates_2.update_fail_malformed_htlcs.is_empty()); assert!(updates_2.update_fee.is_none()); assert_eq!(updates_2.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true); expect_payment_sent!(nodes[0], payment_preimage_0); @@ -188,11 +188,11 @@ fn expect_channel_shutdown_state_with_htlc() { // ClosingSignNegotion process let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -217,12 +217,12 @@ fn test_lnd_bug_6039() { nodes[0].node.close_channel(&chan.2, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); // Generate an lnd-like error message and check that we respond by simply screaming louder to // see if LND will accept our protocol compliance. let err_msg = msgs::ErrorMessage { channel_id: chan.2, data: "link failed to shutdown".to_string() }; - nodes[0].node.handle_error(&nodes[1].node.get_our_node_id(), &err_msg); + nodes[0].node.handle_error(nodes[1].node.get_our_node_id(), &err_msg); let node_a_responses = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(node_a_responses[0], MessageSendEvent::SendShutdown { node_id: nodes[1].node.get_our_node_id(), @@ -239,15 +239,15 @@ fn test_lnd_bug_6039() { claim_payment(&nodes[0], &[&nodes[1]], payment_preimage); // Assume that LND will eventually respond to our Shutdown if we clear all the remaining HTLCs - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); // ClosingSignNegotion process let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -273,7 +273,7 @@ fn shutdown_on_unfunded_channel() { .push_slice(&[0; 20]) .into_script(); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &msgs::Shutdown { + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &msgs::Shutdown { channel_id: open_chan.common_fields.temporary_channel_id, scriptpubkey: script, }); check_closed_event!(nodes[0], 1, ClosureReason::CounterpartyCoopClosedUnfundedChannel, [nodes[1].node.get_our_node_id()], 1_000_000); @@ -345,9 +345,9 @@ fn updates_shutdown_wait() { nodes[0].node.close_channel(&chan_1.2, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -381,7 +381,7 @@ fn updates_shutdown_wait() { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); check_added_monitors!(nodes[1], 1); let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -392,16 +392,16 @@ fn updates_shutdown_wait() { assert!(updates_2.update_fail_malformed_htlcs.is_empty()); assert!(updates_2.update_fee.is_none()); assert_eq!(updates_2.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true); expect_payment_sent!(nodes[0], payment_preimage_0); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -457,13 +457,13 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) { nodes[1].node.close_channel(&chan_1.2, &nodes[0].node.get_our_node_id()).unwrap(); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors!(nodes[1], 1); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); commitment_signed_dance!(nodes[1], nodes[0], (), false, true, false, false); let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -473,7 +473,7 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) { assert!(updates_2.update_fail_malformed_htlcs.is_empty()); assert!(updates_2.update_fee.is_none()); - nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fail_htlcs[0]); + nodes[0].node.handle_update_fail_htlc(nodes[1].node.get_our_node_id(), &updates_2.update_fail_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true); if blinded_recipient { @@ -494,11 +494,11 @@ fn do_htlc_fail_async_shutdown(blinded_recipient: bool) { }; assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); @@ -547,41 +547,41 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { nodes[1].node.close_channel(&chan_1.2, &nodes[0].node.get_our_node_id()).unwrap(); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); if recv_count > 0 { - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); if recv_count > 1 { - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); } } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let node_0_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); let node_1_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &node_0_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &node_0_reestablish); let node_1_2nd_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); assert!(node_1_shutdown == node_1_2nd_shutdown); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &node_1_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &node_1_reestablish); let node_0_2nd_shutdown = if recv_count > 0 { let node_0_2nd_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_2nd_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_2nd_shutdown); node_0_2nd_shutdown } else { let node_0_chan_update = get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id()); assert_eq!(node_0_chan_update.contents.channel_flags & 2, 0); // "disabled" flag must not be set as we just reconnected. - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_2nd_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_2nd_shutdown); get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()) }; - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_2nd_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_2nd_shutdown); assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); @@ -596,7 +596,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { assert!(updates.update_fail_malformed_htlcs.is_empty()); assert!(updates.update_fee.is_none()); assert_eq!(updates.update_fulfill_htlcs.len(), 1); - nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); + nodes[1].node.handle_update_fulfill_htlc(nodes[2].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]); expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false); check_added_monitors!(nodes[1], 1); let updates_2 = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); @@ -607,34 +607,34 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { assert!(updates_2.update_fail_malformed_htlcs.is_empty()); assert!(updates_2.update_fee.is_none()); assert_eq!(updates_2.update_fulfill_htlcs.len(), 1); - nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); + nodes[0].node.handle_update_fulfill_htlc(nodes[1].node.get_our_node_id(), &updates_2.update_fulfill_htlcs[0]); commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true); expect_payment_sent!(nodes[0], payment_preimage); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); if recv_count > 0 { - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); assert!(node_0_2nd_closing_signed.is_some()); } - nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id()); - nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id()); + nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id()); + nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id()); - nodes[1].node.peer_connected(&nodes[0].node.get_our_node_id(), &msgs::Init { + nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init { features: nodes[0].node.init_features(), networks: None, remote_network_address: None }, true).unwrap(); let node_1_2nd_reestablish = get_chan_reestablish_msgs!(nodes[1], nodes[0]).pop().unwrap(); - nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { + nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init { features: nodes[1].node.init_features(), networks: None, remote_network_address: None }, false).unwrap(); if recv_count == 0 { // If all closing_signeds weren't delivered we can just resume where we left off... let node_0_2nd_reestablish = get_chan_reestablish_msgs!(nodes[0], nodes[1]).pop().unwrap(); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &node_1_2nd_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &node_1_2nd_reestablish); let node_0_msgs = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(node_0_msgs.len(), 2); let node_0_2nd_closing_signed = match node_0_msgs[1] { @@ -654,20 +654,20 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { }; assert!(node_0_2nd_shutdown == node_0_3rd_shutdown); - nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &node_0_2nd_reestablish); + nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &node_0_2nd_reestablish); let node_1_3rd_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); assert!(node_1_3rd_shutdown == node_1_2nd_shutdown); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_3rd_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_3rd_shutdown); assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_3rd_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_3rd_shutdown); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); check_closed_event!(nodes[1], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[0].node.get_our_node_id()], 100000); @@ -681,13 +681,13 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) { // transaction. assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); - nodes[0].node.handle_channel_reestablish(&nodes[1].node.get_our_node_id(), &node_1_2nd_reestablish); + nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &node_1_2nd_reestablish); let msg_events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(msg_events.len(), 2); if let MessageSendEvent::HandleError { ref action, .. } = msg_events[1] { match action { &ErrorAction::SendErrorMessage { ref msg } => { - nodes[1].node.handle_error(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_error(nodes[0].node.get_our_node_id(), &msg); assert_eq!(msg.channel_id, chan_1.2); }, _ => panic!("Unexpected event!"), @@ -745,11 +745,11 @@ fn test_upfront_shutdown_script() { node_0_shutdown.scriptpubkey = Builder::new().push_opcode(opcodes::all::OP_RETURN).into_script().to_p2sh(); // Test we enforce upfront_scriptpbukey if by providing a different one at closing that we warn // the peer and ignore the message. - nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[2].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); assert!(regex::Regex::new(r"Got shutdown request with a scriptpubkey \([A-Fa-f0-9]+\) which did not match their previous scriptpubkey.") .unwrap().is_match(&check_warn_msg!(nodes[2], nodes[0].node.get_our_node_id(), chan.2))); // This allows nodes[2] to retry the shutdown message, which should get a response: - nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_orig_shutdown); + nodes[2].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_orig_shutdown); get_event_msg!(nodes[2], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); // We test that in case of peer committing upfront to a script, if it doesn't change at closing, we sign @@ -757,7 +757,7 @@ fn test_upfront_shutdown_script() { nodes[0].node.close_channel(&chan.2, &nodes[2].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[2].node.get_our_node_id()); // We test that in case of peer committing upfront to a script, if it oesn't change at closing, we sign - nodes[2].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[2].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let events = nodes[2].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); match events[0] { @@ -770,7 +770,7 @@ fn test_upfront_shutdown_script() { let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 1000000); nodes[0].node.close_channel(&chan.2, &nodes[1].node.get_our_node_id()).unwrap(); let node_1_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_1_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_1_shutdown); check_added_monitors!(nodes[1], 1); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -786,7 +786,7 @@ fn test_upfront_shutdown_script() { nodes[1].node.close_channel(&chan.2, &nodes[0].node.get_our_node_id()).unwrap(); check_added_monitors!(nodes[1], 1); let node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); match events[0] { @@ -800,7 +800,7 @@ fn test_upfront_shutdown_script() { nodes[1].node.close_channel(&chan.2, &nodes[0].node.get_our_node_id()).unwrap(); check_added_monitors!(nodes[1], 1); let node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); match events[0] { @@ -832,7 +832,7 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() { nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); open_channel.common_fields.shutdown_scriptpubkey = Some(anysegwit_shutdown_script.clone()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -854,10 +854,10 @@ fn test_unsupported_anysegwit_upfront_shutdown_script() { // Check script when handling an accept_channel message nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None, None).unwrap(); let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()); accept_channel.common_fields.shutdown_scriptpubkey = Some(anysegwit_shutdown_script.clone()); - nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel); + nodes[0].node.handle_accept_channel(nodes[1].node.get_our_node_id(), &accept_channel); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -886,7 +886,7 @@ fn test_invalid_upfront_shutdown_script() { open_channel.common_fields.shutdown_scriptpubkey = Some(Builder::new().push_int(0) .push_slice(&[0, 0]) .into_script()); - nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel); + nodes[1].node.handle_open_channel(nodes[0].node.get_our_node_id(), &open_channel); let events = nodes[1].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); @@ -920,7 +920,7 @@ fn test_segwit_v0_shutdown_script() { node_0_shutdown.scriptpubkey = Builder::new().push_int(0) .push_slice(&[0; 20]) .into_script(); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); @@ -955,7 +955,7 @@ fn test_anysegwit_shutdown_script() { node_0_shutdown.scriptpubkey = Builder::new().push_int(16) .push_slice(&[0, 0]) .into_script(); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); let events = nodes[0].node.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 2); @@ -1006,7 +1006,7 @@ fn test_unsupported_anysegwit_shutdown_script() { // Use a non-v0 segwit script unsupported without option_shutdown_anysegwit let mut node_0_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); node_0_shutdown.scriptpubkey = unsupported_shutdown_script.into_inner(); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2), "Got a nonstandard scriptpubkey (60020028) from remote peer"); @@ -1033,7 +1033,7 @@ fn test_invalid_shutdown_script() { node_0_shutdown.scriptpubkey = Builder::new().push_int(0) .push_slice(&[0, 0]) .into_script(); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); assert_eq!(&check_warn_msg!(nodes[0], nodes[1].node.get_our_node_id(), chan.2), "Got a nonstandard scriptpubkey (00020000) from remote peer"); @@ -1117,9 +1117,9 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { nodes[0].node.close_channel(&chan_id, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); { // Now we set nodes[1] to require a relatively high feerate for closing. This should result @@ -1135,7 +1135,7 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { assert!(node_0_closing_signed.fee_satoshis <= 500); if timeout_step != TimeoutStep::AfterShutdown { - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); assert!(check_warn_msg!(nodes[1], nodes[0].node.get_our_node_id(), chan_id) .starts_with("Unable to come to consensus about closing feerate")); @@ -1147,12 +1147,12 @@ fn do_test_closing_signed_reinit_timeout(timeout_step: TimeoutStep) { let mut node_0_peer_state_lock; get_channel_ref!(nodes[0], nodes[1], node_0_per_peer_lock, node_0_peer_state_lock, chan_id).context_mut().closing_fee_limits.as_mut().unwrap().1 *= 10; } - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let node_1_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let node_0_2nd_closing_signed = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); if timeout_step == TimeoutStep::NoTimeout { - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.1.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_2nd_closing_signed.1.unwrap()); check_closed_event!(nodes[1], 1, ClosureReason::CounterpartyInitiatedCooperativeClosure, [nodes[0].node.get_our_node_id()], 100000); } check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -1220,9 +1220,9 @@ fn do_simple_legacy_shutdown_test(high_initiator_fee: bool) { nodes[0].node.close_channel(&chan.2, &nodes[1].node.get_our_node_id()).unwrap(); let node_0_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let mut node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); node_0_closing_signed.fee_range = None; @@ -1232,11 +1232,11 @@ fn do_simple_legacy_shutdown_test(high_initiator_fee: bool) { assert!(node_0_closing_signed.fee_satoshis < 500); } - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let (_, mut node_1_closing_signed) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); node_1_closing_signed.as_mut().unwrap().fee_range = None; - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed.unwrap()); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed.unwrap()); let (_, node_0_none) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); assert!(node_0_none.is_none()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -1265,11 +1265,11 @@ fn simple_target_feerate_shutdown() { nodes[1].node.close_channel_with_feerate_and_script(&chan_id, &nodes[0].node.get_our_node_id(), Some(253 * 5), None).unwrap(); let node_1_shutdown = get_event_msg!(nodes[1], MessageSendEvent::SendShutdown, nodes[0].node.get_our_node_id()); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_0_shutdown); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_1_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_0_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_1_shutdown); let node_0_closing_signed = get_event_msg!(nodes[0], MessageSendEvent::SendClosingSigned, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &node_0_closing_signed); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &node_0_closing_signed); let (_, node_1_closing_signed_opt) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); let node_1_closing_signed = node_1_closing_signed_opt.unwrap(); @@ -1291,7 +1291,7 @@ fn simple_target_feerate_shutdown() { node_0_closing_signed.fee_satoshis); assert_eq!(node_0_closing_signed.fee_satoshis, node_1_closing_signed.fee_satoshis); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &node_1_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &node_1_closing_signed); let (_, node_0_none) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); assert!(node_0_none.is_none()); check_closed_event!(nodes[0], 1, ClosureReason::LocallyInitiatedCooperativeClosure, [nodes[1].node.get_our_node_id()], 100000); @@ -1335,19 +1335,19 @@ fn do_outbound_update_no_early_closing_signed(use_htlc: bool) { nodes[0].node.close_channel(&chan_id, &nodes[1].node.get_our_node_id()).unwrap(); let node_1_shutdown = get_event_msg!(nodes[0], MessageSendEvent::SendShutdown, nodes[1].node.get_our_node_id()); - nodes[0].node.handle_shutdown(&nodes[1].node.get_our_node_id(), &node_0_shutdown); - nodes[1].node.handle_shutdown(&nodes[0].node.get_our_node_id(), &node_1_shutdown); + nodes[0].node.handle_shutdown(nodes[1].node.get_our_node_id(), &node_0_shutdown); + nodes[1].node.handle_shutdown(nodes[0].node.get_our_node_id(), &node_1_shutdown); if use_htlc { - nodes[1].node.handle_update_fail_htlc(&nodes[0].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + nodes[1].node.handle_update_fail_htlc(nodes[0].node.get_our_node_id(), &updates.update_fail_htlcs[0]); } else { - nodes[1].node.handle_update_fee(&nodes[0].node.get_our_node_id(), &updates.update_fee.unwrap()); + nodes[1].node.handle_update_fee(nodes[0].node.get_our_node_id(), &updates.update_fee.unwrap()); } - nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &updates.commitment_signed); + nodes[1].node.handle_commitment_signed(nodes[0].node.get_our_node_id(), &updates.commitment_signed); check_added_monitors(&nodes[1], 1); let (bs_raa, bs_cs) = get_revoke_commit_msgs(&nodes[1], &nodes[0].node.get_our_node_id()); - nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa); + nodes[0].node.handle_revoke_and_ack(nodes[1].node.get_our_node_id(), &bs_raa); check_added_monitors(&nodes[0], 1); // At this point the Channel on nodes[0] has no record of any HTLCs but the latest @@ -1356,7 +1356,7 @@ fn do_outbound_update_no_early_closing_signed(use_htlc: bool) { assert_eq!(nodes[0].node.get_and_clear_pending_msg_events(), Vec::new()); chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress); - nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs); + nodes[0].node.handle_commitment_signed(nodes[1].node.get_our_node_id(), &bs_cs); check_added_monitors(&nodes[0], 1); assert_eq!(nodes[0].node.get_and_clear_pending_msg_events(), Vec::new()); @@ -1369,7 +1369,7 @@ fn do_outbound_update_no_early_closing_signed(use_htlc: bool) { assert_eq!(as_raa_closing_signed.len(), 2); if let MessageSendEvent::SendRevokeAndACK { msg, .. } = &as_raa_closing_signed[0] { - nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_revoke_and_ack(nodes[0].node.get_our_node_id(), &msg); check_added_monitors(&nodes[1], 1); if use_htlc { expect_payment_failed!(nodes[1], payment_hash_opt.unwrap(), true); @@ -1377,13 +1377,13 @@ fn do_outbound_update_no_early_closing_signed(use_htlc: bool) { } else { panic!("Unexpected message {:?}", as_raa_closing_signed[0]); } if let MessageSendEvent::SendClosingSigned { msg, .. } = &as_raa_closing_signed[1] { - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &msg); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &msg); } else { panic!("Unexpected message {:?}", as_raa_closing_signed[1]); } let bs_closing_signed = get_event_msg!(nodes[1], MessageSendEvent::SendClosingSigned, nodes[0].node.get_our_node_id()); - nodes[0].node.handle_closing_signed(&nodes[1].node.get_our_node_id(), &bs_closing_signed); + nodes[0].node.handle_closing_signed(nodes[1].node.get_our_node_id(), &bs_closing_signed); let (_, as_2nd_closing_signed) = get_closing_signed_broadcast!(nodes[0].node, nodes[1].node.get_our_node_id()); - nodes[1].node.handle_closing_signed(&nodes[0].node.get_our_node_id(), &as_2nd_closing_signed.unwrap()); + nodes[1].node.handle_closing_signed(nodes[0].node.get_our_node_id(), &as_2nd_closing_signed.unwrap()); let (_, node_1_none) = get_closing_signed_broadcast!(nodes[1].node, nodes[0].node.get_our_node_id()); assert!(node_1_none.is_none()); diff --git a/lightning/src/ln/types.rs b/lightning/src/ln/types.rs index 659c7e4caba..dbe1e216b90 100644 --- a/lightning/src/ln/types.rs +++ b/lightning/src/ln/types.rs @@ -30,7 +30,8 @@ use bitcoin::hashes::{ HashEngine as _, sha256::Hash as Sha256, }; -use core::fmt; +use bitcoin::hex::display::impl_fmt_traits; +use core::borrow::Borrow; use core::ops::Deref; /// A unique 32-byte identifier for a channel. @@ -41,7 +42,7 @@ use core::ops::Deref; /// A _temporary_ ID is generated randomly. /// (Later revocation-point-based _v2_ is a possibility.) /// The variety (context) is not stored, it is relevant only at creation. -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct ChannelId(pub [u8; 32]); impl ChannelId { @@ -121,9 +122,15 @@ impl Readable for ChannelId { } } -impl fmt::Display for ChannelId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - crate::util::logger::DebugBytes(&self.0).fmt(f) +impl Borrow<[u8]> for ChannelId { + fn borrow(&self) -> &[u8] { + &self.0[..] + } +} + +impl_fmt_traits! { + impl fmt_traits for ChannelId { + const LENGTH: usize = 32; } } diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 865939b078e..648c0fba651 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -714,6 +714,16 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { $contents.supported_quantity() } + /// The public key used by the recipient to sign invoices. + /// + /// From [`Offer::issuer_signing_pubkey`] and may be `None`; also `None` if the invoice was + /// created in response to a [`Refund`]. + /// + /// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey + pub fn issuer_signing_pubkey(&$self) -> Option { + $contents.issuer_signing_pubkey() + } + /// An unpredictable series of bytes from the payer. /// /// From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`]. @@ -739,8 +749,8 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { /// refund in case there are no [`message_paths`]. /// /// [`message_paths`]: Self::message_paths - pub fn payer_id(&$self) -> PublicKey { - $contents.payer_id() + pub fn payer_signing_pubkey(&$self) -> PublicKey { + $contents.payer_signing_pubkey() } /// A payer-provided note reflected back in the invoice. @@ -761,13 +771,36 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { } } } +macro_rules! invoice_accessors_signing_pubkey { + ($self: ident, $contents: expr, $invoice_type: ty) => +{ + /// A typically transient public key corresponding to the key used to sign the invoice. + /// + /// If the invoices was created in response to an [`Offer`], then this will be: + /// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise + /// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`. + /// + /// If the invoice was created in response to a [`Refund`], then it is a valid pubkey chosen by + /// the recipient. + /// + /// [`Offer`]: crate::offers::offer::Offer + /// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey + /// [`Offer::paths`]: crate::offers::offer::Offer::paths + /// [`Refund`]: crate::offers::refund::Refund + pub fn signing_pubkey(&$self) -> PublicKey { + $contents.signing_pubkey() + } +} } + impl UnsignedBolt12Invoice { - invoice_accessors_common!(self, self.contents, Bolt12Invoice); + invoice_accessors_common!(self, self.contents, UnsignedBolt12Invoice); + invoice_accessors_signing_pubkey!(self, self.contents, UnsignedBolt12Invoice); invoice_accessors!(self, self.contents); } impl Bolt12Invoice { invoice_accessors_common!(self, self.contents, Bolt12Invoice); + invoice_accessors_signing_pubkey!(self, self.contents, Bolt12Invoice); invoice_accessors!(self, self.contents); /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`]. @@ -954,6 +987,15 @@ impl InvoiceContents { } } + fn issuer_signing_pubkey(&self) -> Option { + match self { + InvoiceContents::ForOffer { invoice_request, .. } => { + invoice_request.inner.offer.issuer_signing_pubkey() + }, + InvoiceContents::ForRefund { .. } => None, + } + } + fn payer_metadata(&self) -> &[u8] { match self { InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.metadata(), @@ -975,10 +1017,10 @@ impl InvoiceContents { } } - fn payer_id(&self) -> PublicKey { + fn payer_signing_pubkey(&self) -> PublicKey { match self { - InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.payer_id(), - InvoiceContents::ForRefund { refund, .. } => refund.payer_id(), + InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.payer_signing_pubkey(), + InvoiceContents::ForRefund { refund, .. } => refund.payer_signing_pubkey(), } } @@ -1057,9 +1099,9 @@ impl InvoiceContents { }); let tlv_stream = offer_records.chain(invreq_records); - let payer_id = self.payer_id(); + let signing_pubkey = self.payer_signing_pubkey(); signer::verify_payer_metadata( - metadata.as_ref(), key, iv_bytes, payer_id, tlv_stream, secp_ctx, + metadata.as_ref(), key, iv_bytes, signing_pubkey, tlv_stream, secp_ctx, ) } @@ -1335,7 +1377,7 @@ impl TryFrom for InvoiceContents { check_invoice_signing_pubkey(&fields.signing_pubkey, &offer_tlv_stream)?; - if offer_tlv_stream.node_id.is_none() && offer_tlv_stream.paths.is_none() { + if offer_tlv_stream.issuer_id.is_none() && offer_tlv_stream.paths.is_none() { let refund = RefundContents::try_from( (payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream) )?; @@ -1373,9 +1415,9 @@ pub(super) fn construct_payment_paths( pub(super) fn check_invoice_signing_pubkey( invoice_signing_pubkey: &PublicKey, offer_tlv_stream: &OfferTlvStream ) -> Result<(), Bolt12SemanticError> { - match (&offer_tlv_stream.node_id, &offer_tlv_stream.paths) { - (Some(expected_signing_pubkey), _) => { - if invoice_signing_pubkey != expected_signing_pubkey { + match (&offer_tlv_stream.issuer_id, &offer_tlv_stream.paths) { + (Some(issuer_signing_pubkey), _) => { + if invoice_signing_pubkey != issuer_signing_pubkey { return Err(Bolt12SemanticError::InvalidSigningPubkey); } }, @@ -1484,7 +1526,7 @@ mod tests { assert_eq!(unsigned_invoice.amount_msats(), 1000); assert_eq!(unsigned_invoice.invoice_request_features(), &InvoiceRequestFeatures::empty()); assert_eq!(unsigned_invoice.quantity(), None); - assert_eq!(unsigned_invoice.payer_id(), payer_pubkey()); + assert_eq!(unsigned_invoice.payer_signing_pubkey(), payer_pubkey()); assert_eq!(unsigned_invoice.payer_note(), None); assert_eq!(unsigned_invoice.payment_paths(), payment_paths.as_slice()); assert_eq!(unsigned_invoice.created_at(), now); @@ -1526,7 +1568,7 @@ mod tests { assert_eq!(invoice.amount_msats(), 1000); assert_eq!(invoice.invoice_request_features(), &InvoiceRequestFeatures::empty()); assert_eq!(invoice.quantity(), None); - assert_eq!(invoice.payer_id(), payer_pubkey()); + assert_eq!(invoice.payer_signing_pubkey(), payer_pubkey()); assert_eq!(invoice.payer_note(), None); assert_eq!(invoice.payment_paths(), payment_paths.as_slice()); assert_eq!(invoice.created_at(), now); @@ -1561,7 +1603,7 @@ mod tests { paths: None, issuer: None, quantity_max: None, - node_id: Some(&recipient_pubkey()), + issuer_id: Some(&recipient_pubkey()), }, InvoiceRequestTlvStreamRef { chain: None, @@ -1624,7 +1666,7 @@ mod tests { assert_eq!(invoice.amount_msats(), 1000); assert_eq!(invoice.invoice_request_features(), &InvoiceRequestFeatures::empty()); assert_eq!(invoice.quantity(), None); - assert_eq!(invoice.payer_id(), payer_pubkey()); + assert_eq!(invoice.payer_signing_pubkey(), payer_pubkey()); assert_eq!(invoice.payer_note(), None); assert_eq!(invoice.payment_paths(), payment_paths.as_slice()); assert_eq!(invoice.created_at(), now); @@ -1654,7 +1696,7 @@ mod tests { paths: None, issuer: None, quantity_max: None, - node_id: None, + issuer_id: None, }, InvoiceRequestTlvStreamRef { chain: None, @@ -1791,7 +1833,7 @@ mod tests { let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx) .amount_msats(1000) - // Omit the path so that node_id is used for the signing pubkey instead of deriving + // Omit the path so that node_id is used for the signing pubkey instead of deriving it .build().unwrap(); let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() @@ -2359,7 +2401,7 @@ mod tests { }; let invoice = OfferBuilder::new(recipient_pubkey()) - .clear_signing_pubkey() + .clear_issuer_signing_pubkey() .amount_msats(1000) .path(paths[0].clone()) .path(paths[1].clone()) @@ -2381,7 +2423,7 @@ mod tests { } let invoice = OfferBuilder::new(recipient_pubkey()) - .clear_signing_pubkey() + .clear_issuer_signing_pubkey() .amount_msats(1000) .path(paths[0].clone()) .path(paths[1].clone()) diff --git a/lightning/src/offers/invoice_macros.rs b/lightning/src/offers/invoice_macros.rs index 3037ccfa803..579ecd2d20a 100644 --- a/lightning/src/offers/invoice_macros.rs +++ b/lightning/src/offers/invoice_macros.rs @@ -16,7 +16,7 @@ macro_rules! invoice_builder_methods_common { ( #[doc = concat!("Sets the [`", stringify!($invoice_type), "::relative_expiry`]")] #[doc = concat!("as seconds since [`", stringify!($invoice_type), "::created_at`].")] #[doc = "Any expiry that has already passed is valid and can be checked for using"] - #[doc = concat!("[`", stringify!($invoice_type), "::is_expired`].")] + #[cfg_attr(feature = "std", doc = concat!("[`", stringify!($invoice_type), "::is_expired`]."))] /// /// Successive calls to this method will override the previous setting. pub fn relative_expiry($($self_mut)* $self: $self_type, relative_expiry_secs: u32) -> $return_type { @@ -139,11 +139,6 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice pub fn invoice_features(&$self) -> &Bolt12InvoiceFeatures { $contents.features() } - - /// The public key corresponding to the key used to sign the invoice. - pub fn signing_pubkey(&$self) -> PublicKey { - $contents.signing_pubkey() - } } } pub(super) use invoice_accessors_common; diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index fa3d9161b82..c6c9da82a4e 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -36,8 +36,8 @@ //! let pubkey = PublicKey::from(keys); //! let mut buffer = Vec::new(); //! -//! # use lightning::offers::invoice_request::{ExplicitPayerId, InvoiceRequestBuilder}; -//! # >::from( +//! # use lightning::offers::invoice_request::{ExplicitPayerSigningPubkey, InvoiceRequestBuilder}; +//! # >::from( //! "lno1qcp4256ypq" //! .parse::()? //! .request_invoice(vec![42; 64], pubkey)? @@ -102,11 +102,11 @@ pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Invreq ~~~~~"; /// This is not exported to bindings users as builder patterns don't map outside of move semantics. /// /// [module-level documentation]: self -pub struct InvoiceRequestBuilder<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> { +pub struct InvoiceRequestBuilder<'a, 'b, P: PayerSigningPubkeyStrategy, T: secp256k1::Signing> { offer: &'a Offer, - invoice_request: InvoiceRequestContentsWithoutPayerId, - payer_id: Option, - payer_id_strategy: core::marker::PhantomData

, + invoice_request: InvoiceRequestContentsWithoutPayerSigningPubkey, + payer_signing_pubkey: Option, + payer_signing_pubkey_strategy: core::marker::PhantomData

, secp_ctx: Option<&'b Secp256k1>, } @@ -116,11 +116,11 @@ pub struct InvoiceRequestBuilder<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signi /// /// [module-level documentation]: self #[cfg(c_bindings)] -pub struct InvoiceRequestWithExplicitPayerIdBuilder<'a, 'b> { +pub struct InvoiceRequestWithExplicitPayerSigningPubkeyBuilder<'a, 'b> { offer: &'a Offer, - invoice_request: InvoiceRequestContentsWithoutPayerId, - payer_id: Option, - payer_id_strategy: core::marker::PhantomData, + invoice_request: InvoiceRequestContentsWithoutPayerSigningPubkey, + payer_signing_pubkey: Option, + payer_signing_pubkey_strategy: core::marker::PhantomData, secp_ctx: Option<&'b Secp256k1>, } @@ -130,47 +130,47 @@ pub struct InvoiceRequestWithExplicitPayerIdBuilder<'a, 'b> { /// /// [module-level documentation]: self #[cfg(c_bindings)] -pub struct InvoiceRequestWithDerivedPayerIdBuilder<'a, 'b> { +pub struct InvoiceRequestWithDerivedPayerSigningPubkeyBuilder<'a, 'b> { offer: &'a Offer, - invoice_request: InvoiceRequestContentsWithoutPayerId, - payer_id: Option, - payer_id_strategy: core::marker::PhantomData, + invoice_request: InvoiceRequestContentsWithoutPayerSigningPubkey, + payer_signing_pubkey: Option, + payer_signing_pubkey_strategy: core::marker::PhantomData, secp_ctx: Option<&'b Secp256k1>, } -/// Indicates how [`InvoiceRequest::payer_id`] will be set. +/// Indicates how [`InvoiceRequest::payer_signing_pubkey`] will be set. /// /// This is not exported to bindings users as builder patterns don't map outside of move semantics. -pub trait PayerIdStrategy {} +pub trait PayerSigningPubkeyStrategy {} -/// [`InvoiceRequest::payer_id`] will be explicitly set. +/// [`InvoiceRequest::payer_signing_pubkey`] will be explicitly set. /// /// This is not exported to bindings users as builder patterns don't map outside of move semantics. -pub struct ExplicitPayerId {} +pub struct ExplicitPayerSigningPubkey {} -/// [`InvoiceRequest::payer_id`] will be derived. +/// [`InvoiceRequest::payer_signing_pubkey`] will be derived. /// /// This is not exported to bindings users as builder patterns don't map outside of move semantics. -pub struct DerivedPayerId {} +pub struct DerivedPayerSigningPubkey {} -impl PayerIdStrategy for ExplicitPayerId {} -impl PayerIdStrategy for DerivedPayerId {} +impl PayerSigningPubkeyStrategy for ExplicitPayerSigningPubkey {} +impl PayerSigningPubkeyStrategy for DerivedPayerSigningPubkey {} -macro_rules! invoice_request_explicit_payer_id_builder_methods { ($self: ident, $self_type: ty) => { +macro_rules! invoice_request_explicit_payer_signing_pubkey_builder_methods { ($self: ident, $self_type: ty) => { #[cfg_attr(c_bindings, allow(dead_code))] - pub(super) fn new(offer: &'a Offer, metadata: Vec, payer_id: PublicKey) -> Self { + pub(super) fn new(offer: &'a Offer, metadata: Vec, signing_pubkey: PublicKey) -> Self { Self { offer, invoice_request: Self::create_contents(offer, Metadata::Bytes(metadata)), - payer_id: Some(payer_id), - payer_id_strategy: core::marker::PhantomData, + payer_signing_pubkey: Some(signing_pubkey), + payer_signing_pubkey_strategy: core::marker::PhantomData, secp_ctx: None, } } #[cfg_attr(c_bindings, allow(dead_code))] pub(super) fn deriving_metadata( - offer: &'a Offer, payer_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce, + offer: &'a Offer, signing_pubkey: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce, payment_id: PaymentId, ) -> Self { let payment_id = Some(payment_id); @@ -179,8 +179,8 @@ macro_rules! invoice_request_explicit_payer_id_builder_methods { ($self: ident, Self { offer, invoice_request: Self::create_contents(offer, metadata), - payer_id: Some(payer_id), - payer_id_strategy: core::marker::PhantomData, + payer_signing_pubkey: Some(signing_pubkey), + payer_signing_pubkey_strategy: core::marker::PhantomData, secp_ctx: None, } } @@ -194,11 +194,11 @@ macro_rules! invoice_request_explicit_payer_id_builder_methods { ($self: ident, } } } -macro_rules! invoice_request_derived_payer_id_builder_methods { ( +macro_rules! invoice_request_derived_payer_signing_pubkey_builder_methods { ( $self: ident, $self_type: ty, $secp_context: ty ) => { #[cfg_attr(c_bindings, allow(dead_code))] - pub(super) fn deriving_payer_id( + pub(super) fn deriving_signing_pubkey( offer: &'a Offer, expanded_key: &ExpandedKey, nonce: Nonce, secp_ctx: &'b Secp256k1<$secp_context>, payment_id: PaymentId ) -> Self { @@ -208,8 +208,8 @@ macro_rules! invoice_request_derived_payer_id_builder_methods { ( Self { offer, invoice_request: Self::create_contents(offer, metadata), - payer_id: None, - payer_id_strategy: core::marker::PhantomData, + payer_signing_pubkey: None, + payer_signing_pubkey_strategy: core::marker::PhantomData, secp_ctx: Some(secp_ctx), } } @@ -236,9 +236,9 @@ macro_rules! invoice_request_builder_methods { ( $self: ident, $self_type: ty, $return_type: ty, $return_value: expr, $secp_context: ty $(, $self_mut: tt)? ) => { #[cfg_attr(c_bindings, allow(dead_code))] - fn create_contents(offer: &Offer, metadata: Metadata) -> InvoiceRequestContentsWithoutPayerId { + fn create_contents(offer: &Offer, metadata: Metadata) -> InvoiceRequestContentsWithoutPayerSigningPubkey { let offer = offer.contents.clone(); - InvoiceRequestContentsWithoutPayerId { + InvoiceRequestContentsWithoutPayerSigningPubkey { payer: PayerContents(metadata), offer, chain: None, amount_msats: None, features: InvoiceRequestFeatures::empty(), quantity: None, payer_note: None, } @@ -343,7 +343,7 @@ macro_rules! invoice_request_builder_methods { ( debug_assert!(tlv_stream.2.payer_id.is_none()); tlv_stream.0.metadata = None; if !metadata.derives_payer_keys() { - tlv_stream.2.payer_id = $self.payer_id.as_ref(); + tlv_stream.2.payer_id = $self.payer_signing_pubkey.as_ref(); } let (derived_metadata, derived_keys) = @@ -351,23 +351,23 @@ macro_rules! invoice_request_builder_methods { ( metadata = derived_metadata; keys = derived_keys; if let Some(keys) = keys { - debug_assert!($self.payer_id.is_none()); - $self.payer_id = Some(keys.public_key()); + debug_assert!($self.payer_signing_pubkey.is_none()); + $self.payer_signing_pubkey = Some(keys.public_key()); } $self.invoice_request.payer.0 = metadata; } debug_assert!($self.invoice_request.payer.0.as_bytes().is_some()); - debug_assert!($self.payer_id.is_some()); - let payer_id = $self.payer_id.unwrap(); + debug_assert!($self.payer_signing_pubkey.is_some()); + let payer_signing_pubkey = $self.payer_signing_pubkey.unwrap(); let invoice_request = InvoiceRequestContents { #[cfg(not(c_bindings))] inner: $self.invoice_request, #[cfg(c_bindings)] inner: $self.invoice_request.clone(), - payer_id, + payer_signing_pubkey, }; let unsigned_invoice_request = UnsignedInvoiceRequest::new($self.offer, invoice_request); @@ -410,15 +410,15 @@ macro_rules! invoice_request_builder_test_methods { ( } } } -impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerId, T> { - invoice_request_explicit_payer_id_builder_methods!(self, Self); +impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerSigningPubkey, T> { + invoice_request_explicit_payer_signing_pubkey_builder_methods!(self, Self); } -impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T> { - invoice_request_derived_payer_id_builder_methods!(self, Self, T); +impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, DerivedPayerSigningPubkey, T> { + invoice_request_derived_payer_signing_pubkey_builder_methods!(self, Self, T); } -impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, P, T> { +impl<'a, 'b, P: PayerSigningPubkeyStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, P, T> { invoice_request_builder_methods!(self, Self, Self, self, T, mut); #[cfg(test)] @@ -426,55 +426,55 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a } #[cfg(all(c_bindings, not(test)))] -impl<'a, 'b> InvoiceRequestWithExplicitPayerIdBuilder<'a, 'b> { - invoice_request_explicit_payer_id_builder_methods!(self, &mut Self); +impl<'a, 'b> InvoiceRequestWithExplicitPayerSigningPubkeyBuilder<'a, 'b> { + invoice_request_explicit_payer_signing_pubkey_builder_methods!(self, &mut Self); invoice_request_builder_methods!(self, &mut Self, (), (), secp256k1::All); } #[cfg(all(c_bindings, test))] -impl<'a, 'b> InvoiceRequestWithExplicitPayerIdBuilder<'a, 'b> { - invoice_request_explicit_payer_id_builder_methods!(self, &mut Self); +impl<'a, 'b> InvoiceRequestWithExplicitPayerSigningPubkeyBuilder<'a, 'b> { + invoice_request_explicit_payer_signing_pubkey_builder_methods!(self, &mut Self); invoice_request_builder_methods!(self, &mut Self, &mut Self, self, secp256k1::All); invoice_request_builder_test_methods!(self, &mut Self, &mut Self, self); } #[cfg(all(c_bindings, not(test)))] -impl<'a, 'b> InvoiceRequestWithDerivedPayerIdBuilder<'a, 'b> { - invoice_request_derived_payer_id_builder_methods!(self, &mut Self, secp256k1::All); +impl<'a, 'b> InvoiceRequestWithDerivedPayerSigningPubkeyBuilder<'a, 'b> { + invoice_request_derived_payer_signing_pubkey_builder_methods!(self, &mut Self, secp256k1::All); invoice_request_builder_methods!(self, &mut Self, (), (), secp256k1::All); } #[cfg(all(c_bindings, test))] -impl<'a, 'b> InvoiceRequestWithDerivedPayerIdBuilder<'a, 'b> { - invoice_request_derived_payer_id_builder_methods!(self, &mut Self, secp256k1::All); +impl<'a, 'b> InvoiceRequestWithDerivedPayerSigningPubkeyBuilder<'a, 'b> { + invoice_request_derived_payer_signing_pubkey_builder_methods!(self, &mut Self, secp256k1::All); invoice_request_builder_methods!(self, &mut Self, &mut Self, self, secp256k1::All); invoice_request_builder_test_methods!(self, &mut Self, &mut Self, self); } #[cfg(c_bindings)] -impl<'a, 'b> From> -for InvoiceRequestBuilder<'a, 'b, ExplicitPayerId, secp256k1::All> { - fn from(builder: InvoiceRequestWithExplicitPayerIdBuilder<'a, 'b>) -> Self { - let InvoiceRequestWithExplicitPayerIdBuilder { - offer, invoice_request, payer_id, payer_id_strategy, secp_ctx, +impl<'a, 'b> From> +for InvoiceRequestBuilder<'a, 'b, ExplicitPayerSigningPubkey, secp256k1::All> { + fn from(builder: InvoiceRequestWithExplicitPayerSigningPubkeyBuilder<'a, 'b>) -> Self { + let InvoiceRequestWithExplicitPayerSigningPubkeyBuilder { + offer, invoice_request, payer_signing_pubkey, payer_signing_pubkey_strategy, secp_ctx, } = builder; Self { - offer, invoice_request, payer_id, payer_id_strategy, secp_ctx, + offer, invoice_request, payer_signing_pubkey, payer_signing_pubkey_strategy, secp_ctx, } } } #[cfg(c_bindings)] -impl<'a, 'b> From> -for InvoiceRequestBuilder<'a, 'b, DerivedPayerId, secp256k1::All> { - fn from(builder: InvoiceRequestWithDerivedPayerIdBuilder<'a, 'b>) -> Self { - let InvoiceRequestWithDerivedPayerIdBuilder { - offer, invoice_request, payer_id, payer_id_strategy, secp_ctx, +impl<'a, 'b> From> +for InvoiceRequestBuilder<'a, 'b, DerivedPayerSigningPubkey, secp256k1::All> { + fn from(builder: InvoiceRequestWithDerivedPayerSigningPubkeyBuilder<'a, 'b>) -> Self { + let InvoiceRequestWithDerivedPayerSigningPubkeyBuilder { + offer, invoice_request, payer_signing_pubkey, payer_signing_pubkey_strategy, secp_ctx, } = builder; Self { - offer, invoice_request, payer_id, payer_id_strategy, secp_ctx, + offer, invoice_request, payer_signing_pubkey, payer_signing_pubkey_strategy, secp_ctx, } } } @@ -548,7 +548,7 @@ macro_rules! unsigned_invoice_request_sign_method { ( pub fn sign( $($self_mut)* $self: $self_type, sign: F ) -> Result { - let pubkey = $self.contents.payer_id; + let pubkey = $self.contents.payer_signing_pubkey; let signature = merkle::sign_message(sign, &$self, pubkey)?; // Append the signature TLV record to the bytes. @@ -615,12 +615,11 @@ pub struct VerifiedInvoiceRequest { /// Keys used for signing a [`Bolt12Invoice`] if they can be derived. /// - /// If `Some`, must call [`respond_using_derived_keys`] when responding. Otherwise, call - /// [`respond_with`]. - /// + #[cfg_attr(feature = "std", doc = "If `Some`, must call [`respond_using_derived_keys`] when responding. Otherwise, call [`respond_with`].")] + #[cfg_attr(feature = "std", doc = "")] /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice - /// [`respond_using_derived_keys`]: Self::respond_using_derived_keys - /// [`respond_with`]: Self::respond_with + #[cfg_attr(feature = "std", doc = "[`respond_using_derived_keys`]: Self::respond_using_derived_keys")] + #[cfg_attr(feature = "std", doc = "[`respond_with`]: Self::respond_with")] pub keys: Option, } @@ -630,13 +629,13 @@ pub struct VerifiedInvoiceRequest { #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] pub(super) struct InvoiceRequestContents { - pub(super) inner: InvoiceRequestContentsWithoutPayerId, - payer_id: PublicKey, + pub(super) inner: InvoiceRequestContentsWithoutPayerSigningPubkey, + payer_signing_pubkey: PublicKey, } #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] -pub(super) struct InvoiceRequestContentsWithoutPayerId { +pub(super) struct InvoiceRequestContentsWithoutPayerSigningPubkey { pub(super) payer: PayerContents, pub(super) offer: OfferContents, chain: Option, @@ -648,9 +647,9 @@ pub(super) struct InvoiceRequestContentsWithoutPayerId { macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => { /// An unpredictable series of bytes, typically containing information about the derivation of - /// [`payer_id`]. + /// [`payer_signing_pubkey`]. /// - /// [`payer_id`]: Self::payer_id + /// [`payer_signing_pubkey`]: Self::payer_signing_pubkey pub fn payer_metadata(&$self) -> &[u8] { $contents.metadata() } @@ -679,8 +678,8 @@ macro_rules! invoice_request_accessors { ($self: ident, $contents: expr) => { } /// A possibly transient pubkey used to sign the invoice request. - pub fn payer_id(&$self) -> PublicKey { - $contents.payer_id() + pub fn payer_signing_pubkey(&$self) -> PublicKey { + $contents.payer_signing_pubkey() } /// A payer-provided note which will be seen by the recipient and reflected back in the invoice @@ -719,8 +718,8 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { ( /// Creates an [`InvoiceBuilder`] for the request with the given required fields. /// /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after - /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds - /// where [`std::time::SystemTime`] is not available. + /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. + #[cfg_attr(feature = "std", doc = "Useful for non-`std` builds where [`std::time::SystemTime`] is not available.")] /// /// The caller is expected to remember the preimage of `payment_hash` in order to claim a payment /// for the invoice. @@ -728,7 +727,7 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { ( /// The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It /// must contain one or more elements ordered from most-preferred to least-preferred, if there's /// a preference. Note, however, that any privacy is lost if a public node id was used for - /// [`Offer::signing_pubkey`]. + /// [`Offer::issuer_signing_pubkey`]. /// /// Errors if the request contains unknown required features. /// @@ -749,9 +748,9 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { ( return Err(Bolt12SemanticError::UnknownRequiredFeatures); } - let signing_pubkey = match $contents.contents.inner.offer.signing_pubkey() { + let signing_pubkey = match $contents.contents.inner.offer.issuer_signing_pubkey() { Some(signing_pubkey) => signing_pubkey, - None => return Err(Bolt12SemanticError::MissingSigningPubkey), + None => return Err(Bolt12SemanticError::MissingIssuerSigningPubkey), }; <$builder>::for_offer(&$contents, payment_paths, created_at, payment_hash, signing_pubkey) @@ -763,7 +762,7 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { ( &$self, payment_paths: Vec, payment_hash: PaymentHash, created_at: core::time::Duration, signing_pubkey: PublicKey ) -> Result<$builder, Bolt12SemanticError> { - debug_assert!($contents.contents.inner.offer.signing_pubkey().is_none()); + debug_assert!($contents.contents.inner.offer.issuer_signing_pubkey().is_none()); if $contents.invoice_request_features().requires_unknown_bits() { return Err(Bolt12SemanticError::UnknownRequiredFeatures); @@ -840,6 +839,11 @@ impl InvoiceRequest { invoice_request_accessors!(self, self.contents); invoice_request_respond_with_explicit_signing_pubkey_methods!(self, self, InvoiceBuilder); invoice_request_verify_method!(self, Self); + + #[cfg(async_payments)] + pub(super) fn bytes(&self) -> &Vec { + &self.bytes + } } #[cfg(c_bindings)] @@ -851,9 +855,9 @@ impl InvoiceRequest { } impl InvoiceRequest { - /// Signature of the invoice request using [`payer_id`]. + /// Signature of the invoice request using [`payer_signing_pubkey`]. /// - /// [`payer_id`]: Self::payer_id + /// [`payer_signing_pubkey`]: Self::payer_signing_pubkey pub fn signature(&self) -> Signature { self.signature } @@ -909,9 +913,9 @@ macro_rules! invoice_request_respond_with_derived_signing_pubkey_methods { ( Some(keys) => keys, }; - match $contents.contents.inner.offer.signing_pubkey() { + match $contents.contents.inner.offer.issuer_signing_pubkey() { Some(signing_pubkey) => debug_assert_eq!(signing_pubkey, keys.public_key()), - None => return Err(Bolt12SemanticError::MissingSigningPubkey), + None => return Err(Bolt12SemanticError::MissingIssuerSigningPubkey), } <$builder>::for_offer_using_keys( @@ -934,14 +938,14 @@ impl VerifiedInvoiceRequest { pub(crate) fn fields(&self) -> InvoiceRequestFields { let InvoiceRequestContents { - payer_id, - inner: InvoiceRequestContentsWithoutPayerId { + payer_signing_pubkey, + inner: InvoiceRequestContentsWithoutPayerSigningPubkey { payer: _, offer: _, chain: _, amount_msats: _, features: _, quantity, payer_note }, } = &self.inner.contents; InvoiceRequestFields { - payer_id: *payer_id, + payer_signing_pubkey: *payer_signing_pubkey, quantity: *quantity, payer_note_truncated: payer_note.clone() .map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }), @@ -970,8 +974,8 @@ impl InvoiceRequestContents { self.inner.quantity } - pub(super) fn payer_id(&self) -> PublicKey { - self.payer_id + pub(super) fn payer_signing_pubkey(&self) -> PublicKey { + self.payer_signing_pubkey } pub(super) fn payer_note(&self) -> Option { @@ -981,12 +985,12 @@ impl InvoiceRequestContents { pub(super) fn as_tlv_stream(&self) -> PartialInvoiceRequestTlvStreamRef { let (payer, offer, mut invoice_request) = self.inner.as_tlv_stream(); - invoice_request.payer_id = Some(&self.payer_id); + invoice_request.payer_id = Some(&self.payer_signing_pubkey); (payer, offer, invoice_request) } } -impl InvoiceRequestContentsWithoutPayerId { +impl InvoiceRequestContentsWithoutPayerSigningPubkey { pub(super) fn metadata(&self) -> &[u8] { self.payer.0.as_bytes().map(|bytes| bytes.as_slice()).unwrap_or(&[]) } @@ -1039,12 +1043,20 @@ impl Writeable for InvoiceRequestContents { } } +impl Readable for InvoiceRequest { + fn read(reader: &mut R) -> Result { + let bytes: WithoutLength> = Readable::read(reader)?; + Self::try_from(bytes.0).map_err(|_| DecodeError::InvalidValue) + } +} + /// Valid type range for invoice_request TLV records. pub(super) const INVOICE_REQUEST_TYPES: core::ops::Range = 80..160; -/// TLV record type for [`InvoiceRequest::payer_id`] and [`Refund::payer_id`]. +/// TLV record type for [`InvoiceRequest::payer_signing_pubkey`] and +/// [`Refund::payer_signing_pubkey`]. /// -/// [`Refund::payer_id`]: crate::offers::refund::Refund::payer_id +/// [`Refund::payer_signing_pubkey`]: crate::offers::refund::Refund::payer_signing_pubkey pub(super) const INVOICE_REQUEST_PAYER_ID_TYPE: u64 = 88; // This TLV stream is used for both InvoiceRequest and Refund, but not all TLV records are valid for @@ -1127,7 +1139,7 @@ impl TryFrom> for InvoiceRequest { Some(signature) => signature, }; let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &bytes); - merkle::verify_signature(&signature, &message, contents.payer_id)?; + merkle::verify_signature(&signature, &message, contents.payer_signing_pubkey)?; Ok(InvoiceRequest { bytes, contents, signature }) } @@ -1164,8 +1176,8 @@ impl TryFrom for InvoiceRequestContents { let features = features.unwrap_or_else(InvoiceRequestFeatures::empty); - let payer_id = match payer_id { - None => return Err(Bolt12SemanticError::MissingPayerId), + let payer_signing_pubkey = match payer_id { + None => return Err(Bolt12SemanticError::MissingPayerSigningPubkey), Some(payer_id) => payer_id, }; @@ -1174,10 +1186,10 @@ impl TryFrom for InvoiceRequestContents { } Ok(InvoiceRequestContents { - inner: InvoiceRequestContentsWithoutPayerId { + inner: InvoiceRequestContentsWithoutPayerSigningPubkey { payer, offer, chain, amount_msats: amount, features, quantity, payer_note, }, - payer_id, + payer_signing_pubkey, }) } } @@ -1188,7 +1200,7 @@ impl TryFrom for InvoiceRequestContents { #[derive(Clone, Debug, Eq, PartialEq)] pub struct InvoiceRequestFields { /// A possibly transient pubkey used to sign the invoice request. - pub payer_id: PublicKey, + pub payer_signing_pubkey: PublicKey, /// The quantity of the offer's item conforming to [`Offer::is_valid_quantity`]. pub quantity: Option, @@ -1204,7 +1216,7 @@ pub const PAYER_NOTE_LIMIT: usize = 512; impl Writeable for InvoiceRequestFields { fn write(&self, writer: &mut W) -> Result<(), io::Error> { write_tlv_fields!(writer, { - (0, self.payer_id, required), + (0, self.payer_signing_pubkey, required), (2, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option), (4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option), }); @@ -1215,13 +1227,13 @@ impl Writeable for InvoiceRequestFields { impl Readable for InvoiceRequestFields { fn read(reader: &mut R) -> Result { _init_and_read_len_prefixed_tlv_fields!(reader, { - (0, payer_id, required), + (0, payer_signing_pubkey, required), (2, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), (4, payer_note_truncated, (option, encoding: (String, WithoutLength))), }); Ok(InvoiceRequestFields { - payer_id: payer_id.0.unwrap(), + payer_signing_pubkey: payer_signing_pubkey.0.unwrap(), quantity, payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)), }) @@ -1285,12 +1297,12 @@ mod tests { assert_eq!(unsigned_invoice_request.paths(), &[]); assert_eq!(unsigned_invoice_request.issuer(), None); assert_eq!(unsigned_invoice_request.supported_quantity(), Quantity::One); - assert_eq!(unsigned_invoice_request.signing_pubkey(), Some(recipient_pubkey())); + assert_eq!(unsigned_invoice_request.issuer_signing_pubkey(), Some(recipient_pubkey())); assert_eq!(unsigned_invoice_request.chain(), ChainHash::using_genesis_block(Network::Bitcoin)); assert_eq!(unsigned_invoice_request.amount_msats(), None); assert_eq!(unsigned_invoice_request.invoice_request_features(), &InvoiceRequestFeatures::empty()); assert_eq!(unsigned_invoice_request.quantity(), None); - assert_eq!(unsigned_invoice_request.payer_id(), payer_pubkey()); + assert_eq!(unsigned_invoice_request.payer_signing_pubkey(), payer_pubkey()); assert_eq!(unsigned_invoice_request.payer_note(), None); match UnsignedInvoiceRequest::try_from(buffer) { @@ -1317,12 +1329,12 @@ mod tests { assert_eq!(invoice_request.paths(), &[]); assert_eq!(invoice_request.issuer(), None); assert_eq!(invoice_request.supported_quantity(), Quantity::One); - assert_eq!(invoice_request.signing_pubkey(), Some(recipient_pubkey())); + assert_eq!(invoice_request.issuer_signing_pubkey(), Some(recipient_pubkey())); assert_eq!(invoice_request.chain(), ChainHash::using_genesis_block(Network::Bitcoin)); assert_eq!(invoice_request.amount_msats(), None); assert_eq!(invoice_request.invoice_request_features(), &InvoiceRequestFeatures::empty()); assert_eq!(invoice_request.quantity(), None); - assert_eq!(invoice_request.payer_id(), payer_pubkey()); + assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey()); assert_eq!(invoice_request.payer_note(), None); let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice_request.bytes); @@ -1343,7 +1355,7 @@ mod tests { paths: None, issuer: None, quantity_max: None, - node_id: Some(&recipient_pubkey()), + issuer_id: Some(&recipient_pubkey()), }, InvoiceRequestTlvStreamRef { chain: None, @@ -1393,7 +1405,7 @@ mod tests { #[test] fn builds_invoice_request_with_derived_metadata() { - let payer_id = payer_pubkey(); + let signing_pubkey = payer_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; let nonce = Nonce::from_entropy_source(&entropy); @@ -1404,11 +1416,11 @@ mod tests { .amount_msats(1000) .build().unwrap(); let invoice_request = offer - .request_invoice_deriving_metadata(payer_id, &expanded_key, nonce, payment_id) + .request_invoice_deriving_metadata(signing_pubkey, &expanded_key, nonce, payment_id) .unwrap() .build().unwrap() .sign(payer_sign).unwrap(); - assert_eq!(invoice_request.payer_id(), payer_pubkey()); + assert_eq!(invoice_request.payer_signing_pubkey(), payer_pubkey()); let invoice = invoice_request.respond_with_no_std(payment_paths(), payment_hash(), now()) .unwrap() @@ -1470,7 +1482,7 @@ mod tests { } #[test] - fn builds_invoice_request_with_derived_payer_id() { + fn builds_invoice_request_with_derived_payer_signing_pubkey() { let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; let nonce = Nonce::from_entropy_source(&entropy); @@ -1481,7 +1493,7 @@ mod tests { .amount_msats(1000) .build().unwrap(); let invoice_request = offer - .request_invoice_deriving_payer_id(&expanded_key, nonce, &secp_ctx, payment_id) + .request_invoice_deriving_signing_pubkey(&expanded_key, nonce, &secp_ctx, payment_id) .unwrap() .build_and_sign() .unwrap(); @@ -2203,7 +2215,7 @@ mod tests { } #[test] - fn fails_parsing_invoice_request_without_payer_id() { + fn fails_parsing_invoice_request_without_payer_signing_pubkey() { let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); @@ -2217,19 +2229,19 @@ mod tests { match InvoiceRequest::try_from(buffer) { Ok(_) => panic!("expected error"), - Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId)), + Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerSigningPubkey)), } } #[test] - fn fails_parsing_invoice_request_without_node_id() { + fn fails_parsing_invoice_request_without_issuer_id() { let offer = OfferBuilder::new(recipient_pubkey()) .amount_msats(1000) .build().unwrap(); let unsigned_invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap(); let mut tlv_stream = unsigned_invoice_request.contents.as_tlv_stream(); - tlv_stream.1.node_id = None; + tlv_stream.1.issuer_id = None; let mut buffer = Vec::new(); tlv_stream.write(&mut buffer).unwrap(); @@ -2237,7 +2249,7 @@ mod tests { match InvoiceRequest::try_from(buffer) { Ok(_) => panic!("expected error"), Err(e) => { - assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey)); + assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingIssuerSigningPubkey)); }, } } @@ -2322,7 +2334,7 @@ mod tests { .amount_msats(1000) .supported_quantity(Quantity::Unbounded) .build().unwrap(); - assert_eq!(offer.signing_pubkey(), Some(node_id)); + assert_eq!(offer.issuer_signing_pubkey(), Some(node_id)); let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .chain(Network::Testnet).unwrap() @@ -2337,7 +2349,7 @@ mod tests { assert_eq!( fields, InvoiceRequestFields { - payer_id: payer_pubkey(), + payer_signing_pubkey: payer_pubkey(), quantity: Some(1), payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))), } diff --git a/lightning/src/offers/merkle.rs b/lightning/src/offers/merkle.rs index 90bfc859e50..e2fed2e800b 100644 --- a/lightning/src/offers/merkle.rs +++ b/lightning/src/offers/merkle.rs @@ -249,6 +249,7 @@ impl<'a> TlvStream<'a> { } /// A slice into a [`TlvStream`] for a record. +#[derive(Eq, PartialEq)] pub(super) struct TlvRecord<'a> { pub(super) r#type: u64, type_bytes: &'a [u8], diff --git a/lightning/src/offers/nonce.rs b/lightning/src/offers/nonce.rs index 1dd21e6c83d..0675414125f 100644 --- a/lightning/src/offers/nonce.rs +++ b/lightning/src/offers/nonce.rs @@ -20,11 +20,11 @@ use crate::prelude::*; /// A 128-bit number used only once. /// -/// Needed when constructing [`Offer::metadata`] and deriving [`Offer::signing_pubkey`] from +/// Needed when constructing [`Offer::metadata`] and deriving [`Offer::issuer_signing_pubkey`] from /// [`ExpandedKey`]. Must not be reused for any other derivation without first hashing. /// /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata -/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey +/// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct Nonce(pub(crate) [u8; Self::LENGTH]); diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 27a79166bc3..8501b8d4651 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -99,11 +99,11 @@ use crate::util::string::PrintableString; #[cfg(not(c_bindings))] use { - crate::offers::invoice_request::{DerivedPayerId, ExplicitPayerId, InvoiceRequestBuilder}, + crate::offers::invoice_request::{DerivedPayerSigningPubkey, ExplicitPayerSigningPubkey, InvoiceRequestBuilder}, }; #[cfg(c_bindings)] use { - crate::offers::invoice_request::{InvoiceRequestWithDerivedPayerIdBuilder, InvoiceRequestWithExplicitPayerIdBuilder}, + crate::offers::invoice_request::{InvoiceRequestWithDerivedPayerSigningPubkeyBuilder, InvoiceRequestWithExplicitPayerSigningPubkeyBuilder}, }; #[allow(unused_imports)] @@ -207,8 +207,8 @@ impl MetadataStrategy for DerivedMetadata {} macro_rules! offer_explicit_metadata_builder_methods { ( $self: ident, $self_type: ty, $return_type: ty, $return_value: expr ) => { - /// Creates a new builder for an offer using the [`Offer::signing_pubkey`] for signing invoices. - /// The associated secret key must be remembered while the offer is valid. + /// Creates a new builder for an offer using the `signing_pubkey` for signing invoices. The + /// associated secret key must be remembered while the offer is valid. /// /// Use a different pubkey per offer to avoid correlating offers. /// @@ -224,7 +224,7 @@ macro_rules! offer_explicit_metadata_builder_methods { ( offer: OfferContents { chains: None, metadata: None, amount: None, description: None, features: OfferFeatures::empty(), absolute_expiry: None, issuer: None, paths: None, - supported_quantity: Quantity::One, signing_pubkey: Some(signing_pubkey), + supported_quantity: Quantity::One, issuer_signing_pubkey: Some(signing_pubkey), }, metadata_strategy: core::marker::PhantomData, secp_ctx: None, @@ -244,7 +244,7 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => { /// Similar to [`OfferBuilder::new`] except, if [`OfferBuilder::path`] is called, the signing /// pubkey is derived from the given [`ExpandedKey`] and [`Nonce`]. This provides recipient /// privacy by using a different signing pubkey for each offer. Otherwise, the provided - /// `node_id` is used for the signing pubkey. + /// `node_id` is used for [`Offer::issuer_signing_pubkey`]. /// /// Also, sets the metadata when [`OfferBuilder::build`] is called such that it can be used by /// [`InvoiceRequest::verify_using_metadata`] to determine if the request was produced for the @@ -265,7 +265,7 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => { offer: OfferContents { chains: None, metadata: Some(metadata), amount: None, description: None, features: OfferFeatures::empty(), absolute_expiry: None, issuer: None, paths: None, - supported_quantity: Quantity::One, signing_pubkey: Some(node_id), + supported_quantity: Quantity::One, issuer_signing_pubkey: Some(node_id), }, metadata_strategy: core::marker::PhantomData, secp_ctx: Some(secp_ctx), @@ -316,8 +316,8 @@ macro_rules! offer_builder_methods { ( $return_value } - /// Sets the [`Offer::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has - /// already passed is valid and can be checked for using [`Offer::is_expired`]. + /// Sets the [`Offer::absolute_expiry`] as seconds since the Unix epoch. + #[cfg_attr(feature = "std", doc = "Any expiry that has already passed is valid and can be checked for using [`Offer::is_expired`].")] /// /// Successive calls to this method will override the previous setting. pub fn absolute_expiry($($self_mut)* $self: $self_type, absolute_expiry: Duration) -> $return_type { @@ -342,7 +342,7 @@ macro_rules! offer_builder_methods { ( } /// Adds a blinded path to [`Offer::paths`]. Must include at least one path if only connected by - /// private channels or if [`Offer::signing_pubkey`] is not a public node id. + /// private channels or if [`Offer::issuer_signing_pubkey`] is not a public node id. /// /// Successive calls to this method will add another blinded path. Caller is responsible for not /// adding duplicate paths. @@ -403,7 +403,7 @@ macro_rules! offer_builder_methods { ( debug_assert_eq!(tlv_stream.metadata, None); tlv_stream.metadata = None; if metadata.derives_recipient_keys() { - tlv_stream.node_id = None; + tlv_stream.issuer_id = None; } // Either replace the signing pubkey with the derived pubkey or include the metadata @@ -412,7 +412,7 @@ macro_rules! offer_builder_methods { ( let (derived_metadata, keys) = metadata.derive_from(iv_bytes, tlv_stream, $self.secp_ctx); match keys { - Some(keys) => $self.offer.signing_pubkey = Some(keys.public_key()), + Some(keys) => $self.offer.issuer_signing_pubkey = Some(keys.public_key()), None => $self.offer.metadata = Some(derived_metadata), } } else { @@ -459,8 +459,8 @@ macro_rules! offer_builder_test_methods { ( } #[cfg_attr(c_bindings, allow(dead_code))] - pub(crate) fn clear_signing_pubkey($($self_mut)* $self: $self_type) -> $return_type { - $self.offer.signing_pubkey = None; + pub(crate) fn clear_issuer_signing_pubkey($($self_mut)* $self: $self_type) -> $return_type { + $self.offer.issuer_signing_pubkey = None; $return_value } @@ -570,7 +570,7 @@ pub(super) struct OfferContents { issuer: Option, paths: Option>, supported_quantity: Quantity, - signing_pubkey: Option, + issuer_signing_pubkey: Option, } macro_rules! offer_accessors { ($self: ident, $contents: expr) => { @@ -631,9 +631,19 @@ macro_rules! offer_accessors { ($self: ident, $contents: expr) => { $contents.supported_quantity() } - /// The public key used by the recipient to sign invoices. - pub fn signing_pubkey(&$self) -> Option { - $contents.signing_pubkey() + /// The public key corresponding to the key used by the recipient to sign invoices. + /// - If [`Offer::paths`] is empty, MUST be `Some` and contain the recipient's node id for + /// sending an [`InvoiceRequest`]. + /// - If [`Offer::paths`] is not empty, MAY be `Some` and contain a transient id. + /// - If `None`, the signing pubkey will be the final blinded node id from the + /// [`BlindedMessagePath`] in [`Offer::paths`] used to send the [`InvoiceRequest`]. + /// + /// See also [`Bolt12Invoice::signing_pubkey`]. + /// + /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest + /// [`Bolt12Invoice::signing_pubkey`]: crate::offers::invoice::Bolt12Invoice::signing_pubkey + pub fn issuer_signing_pubkey(&$self) -> Option { + $contents.issuer_signing_pubkey() } } } @@ -685,10 +695,10 @@ impl Offer { } } -macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) => { +macro_rules! request_invoice_derived_signing_pubkey { ($self: ident, $builder: ty) => { /// Similar to [`Offer::request_invoice`] except it: - /// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each - /// request, + /// - derives the [`InvoiceRequest::payer_signing_pubkey`] such that a different key can be used + /// for each request, /// - sets [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is called /// such that it can be used by [`Bolt12Invoice::verify_using_metadata`] to determine if the /// invoice was requested using a base [`ExpandedKey`] from which the payer id was derived, @@ -698,11 +708,11 @@ macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) => /// /// Useful to protect the sender's privacy. /// - /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id + /// [`InvoiceRequest::payer_signing_pubkey`]: crate::offers::invoice_request::InvoiceRequest::payer_signing_pubkey /// [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata /// [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey - pub fn request_invoice_deriving_payer_id< + pub fn request_invoice_deriving_signing_pubkey< 'a, 'b, #[cfg(not(c_bindings))] T: secp256k1::Signing @@ -718,34 +728,35 @@ macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) => return Err(Bolt12SemanticError::UnknownRequiredFeatures); } - Ok(<$builder>::deriving_payer_id($self, expanded_key, nonce, secp_ctx, payment_id)) + Ok(<$builder>::deriving_signing_pubkey($self, expanded_key, nonce, secp_ctx, payment_id)) } } } -macro_rules! request_invoice_explicit_payer_id { ($self: ident, $builder: ty) => { - /// Similar to [`Offer::request_invoice_deriving_payer_id`] except uses `payer_id` for the - /// [`InvoiceRequest::payer_id`] instead of deriving a different key for each request. +macro_rules! request_invoice_explicit_signing_pubkey { ($self: ident, $builder: ty) => { + /// Similar to [`Offer::request_invoice_deriving_signing_pubkey`] except uses `signing_pubkey` + /// for the [`InvoiceRequest::payer_signing_pubkey`] instead of deriving a different key for + /// each request. /// - /// Useful for recurring payments using the same `payer_id` with different invoices. + /// Useful for recurring payments using the same `signing_pubkey` with different invoices. /// - /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id + /// [`InvoiceRequest::payer_signing_pubkey`]: crate::offers::invoice_request::InvoiceRequest::payer_signing_pubkey pub fn request_invoice_deriving_metadata( - &$self, payer_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce, + &$self, signing_pubkey: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce, payment_id: PaymentId ) -> Result<$builder, Bolt12SemanticError> { if $self.offer_features().requires_unknown_bits() { return Err(Bolt12SemanticError::UnknownRequiredFeatures); } - Ok(<$builder>::deriving_metadata($self, payer_id, expanded_key, nonce, payment_id)) + Ok(<$builder>::deriving_metadata($self, signing_pubkey, expanded_key, nonce, payment_id)) } - /// Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`, - /// which will be reflected in the `Bolt12Invoice` response. + /// Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and + /// `signing_pubkey`, which will be reflected in the `Bolt12Invoice` response. /// - /// The `metadata` is useful for including information about the derivation of `payer_id` such - /// that invoice response handling can be stateless. Also serves as payer-provided entropy while - /// hashing in the signature calculation. + /// The `metadata` is useful for including information about the derivation of `signing_pubkey` + /// such that invoice response handling can be stateless. Also serves as payer-provided entropy + /// while hashing in the signature calculation. /// /// This should not leak any information such as by using a simple BIP-32 derivation path. /// Otherwise, payments may be correlated. @@ -754,26 +765,26 @@ macro_rules! request_invoice_explicit_payer_id { ($self: ident, $builder: ty) => /// /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest pub fn request_invoice( - &$self, metadata: Vec, payer_id: PublicKey + &$self, metadata: Vec, signing_pubkey: PublicKey ) -> Result<$builder, Bolt12SemanticError> { if $self.offer_features().requires_unknown_bits() { return Err(Bolt12SemanticError::UnknownRequiredFeatures); } - Ok(<$builder>::new($self, metadata, payer_id)) + Ok(<$builder>::new($self, metadata, signing_pubkey)) } } } #[cfg(not(c_bindings))] impl Offer { - request_invoice_derived_payer_id!(self, InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T>); - request_invoice_explicit_payer_id!(self, InvoiceRequestBuilder); + request_invoice_derived_signing_pubkey!(self, InvoiceRequestBuilder<'a, 'b, DerivedPayerSigningPubkey, T>); + request_invoice_explicit_signing_pubkey!(self, InvoiceRequestBuilder); } #[cfg(c_bindings)] impl Offer { - request_invoice_derived_payer_id!(self, InvoiceRequestWithDerivedPayerIdBuilder<'a, 'b>); - request_invoice_explicit_payer_id!(self, InvoiceRequestWithExplicitPayerIdBuilder); + request_invoice_derived_signing_pubkey!(self, InvoiceRequestWithDerivedPayerSigningPubkeyBuilder<'a, 'b>); + request_invoice_explicit_signing_pubkey!(self, InvoiceRequestWithExplicitPayerSigningPubkeyBuilder); } #[cfg(test)] @@ -916,8 +927,8 @@ impl OfferContents { } } - pub(super) fn signing_pubkey(&self) -> Option { - self.signing_pubkey + pub(super) fn issuer_signing_pubkey(&self) -> Option { + self.issuer_signing_pubkey } pub(super) fn verify_using_metadata( @@ -943,11 +954,11 @@ impl OfferContents { let tlv_stream = TlvStream::new(bytes).range(OFFER_TYPES).filter(|record| { match record.r#type { OFFER_METADATA_TYPE => false, - OFFER_NODE_ID_TYPE => !metadata.derives_recipient_keys(), + OFFER_ISSUER_ID_TYPE => !metadata.derives_recipient_keys(), _ => true, } }); - let signing_pubkey = match self.signing_pubkey() { + let signing_pubkey = match self.issuer_signing_pubkey() { Some(signing_pubkey) => signing_pubkey, None => return Err(()), }; @@ -987,7 +998,7 @@ impl OfferContents { paths: self.paths.as_ref(), issuer: self.issuer.as_ref(), quantity_max: self.supported_quantity.to_tlv_record(), - node_id: self.signing_pubkey.as_ref(), + issuer_id: self.issuer_signing_pubkey.as_ref(), } } } @@ -1063,8 +1074,8 @@ pub(super) const OFFER_TYPES: core::ops::Range = 1..80; /// TLV record type for [`Offer::metadata`]. const OFFER_METADATA_TYPE: u64 = 4; -/// TLV record type for [`Offer::signing_pubkey`]. -const OFFER_NODE_ID_TYPE: u64 = 22; +/// TLV record type for [`Offer::issuer_signing_pubkey`]. +const OFFER_ISSUER_ID_TYPE: u64 = 22; tlv_stream!(OfferTlvStream, OfferTlvStreamRef, OFFER_TYPES, { (2, chains: (Vec, WithoutLength)), @@ -1077,7 +1088,7 @@ tlv_stream!(OfferTlvStream, OfferTlvStreamRef, OFFER_TYPES, { (16, paths: (Vec, WithoutLength)), (18, issuer: (String, WithoutLength)), (20, quantity_max: (u64, HighZeroBytesDroppedBigSize)), - (OFFER_NODE_ID_TYPE, node_id: PublicKey), + (OFFER_ISSUER_ID_TYPE, issuer_id: PublicKey), }); impl Bech32Encode for Offer { @@ -1111,7 +1122,7 @@ impl TryFrom for OfferContents { fn try_from(tlv_stream: OfferTlvStream) -> Result { let OfferTlvStream { chains, metadata, currency, amount, description, features, absolute_expiry, paths, - issuer, quantity_max, node_id, + issuer, quantity_max, issuer_id, } = tlv_stream; let metadata = metadata.map(|metadata| Metadata::Bytes(metadata)); @@ -1141,15 +1152,15 @@ impl TryFrom for OfferContents { Some(n) => Quantity::Bounded(NonZeroU64::new(n).unwrap()), }; - let (signing_pubkey, paths) = match (node_id, paths) { - (None, None) => return Err(Bolt12SemanticError::MissingSigningPubkey), + let (issuer_signing_pubkey, paths) = match (issuer_id, paths) { + (None, None) => return Err(Bolt12SemanticError::MissingIssuerSigningPubkey), (_, Some(paths)) if paths.is_empty() => return Err(Bolt12SemanticError::MissingPaths), - (node_id, paths) => (node_id, paths), + (issuer_id, paths) => (issuer_id, paths), }; Ok(OfferContents { chains, metadata, amount, description, features, absolute_expiry, issuer, paths, - supported_quantity, signing_pubkey, + supported_quantity, issuer_signing_pubkey, }) } } @@ -1210,7 +1221,7 @@ mod tests { assert_eq!(offer.issuer(), None); assert_eq!(offer.supported_quantity(), Quantity::One); assert!(!offer.expects_quantity()); - assert_eq!(offer.signing_pubkey(), Some(pubkey(42))); + assert_eq!(offer.issuer_signing_pubkey(), Some(pubkey(42))); assert_eq!( offer.as_tlv_stream(), @@ -1225,7 +1236,7 @@ mod tests { paths: None, issuer: None, quantity_max: None, - node_id: Some(&pubkey(42)), + issuer_id: Some(&pubkey(42)), }, ); @@ -1307,7 +1318,7 @@ mod tests { .amount_msats(1000) .build().unwrap(); assert!(offer.metadata().is_some()); - assert_eq!(offer.signing_pubkey(), Some(node_id)); + assert_eq!(offer.issuer_signing_pubkey(), Some(node_id)); let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() @@ -1376,7 +1387,7 @@ mod tests { .path(blinded_path) .build().unwrap(); assert!(offer.metadata().is_none()); - assert_ne!(offer.signing_pubkey(), Some(node_id)); + assert_ne!(offer.issuer_signing_pubkey(), Some(node_id)); let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() @@ -1409,8 +1420,8 @@ mod tests { // Fails verification with altered signing pubkey let mut tlv_stream = offer.as_tlv_stream(); - let signing_pubkey = pubkey(1); - tlv_stream.node_id = Some(&signing_pubkey); + let issuer_id = pubkey(1); + tlv_stream.issuer_id = Some(&issuer_id); let mut encoded_offer = Vec::new(); tlv_stream.write(&mut encoded_offer).unwrap(); @@ -1567,10 +1578,10 @@ mod tests { .unwrap(); let tlv_stream = offer.as_tlv_stream(); assert_eq!(offer.paths(), paths.as_slice()); - assert_eq!(offer.signing_pubkey(), Some(pubkey(42))); + assert_eq!(offer.issuer_signing_pubkey(), Some(pubkey(42))); assert_ne!(pubkey(42), pubkey(44)); assert_eq!(tlv_stream.paths, Some(&paths)); - assert_eq!(tlv_stream.node_id, Some(&pubkey(42))); + assert_eq!(tlv_stream.issuer_id, Some(&pubkey(42))); } #[test] @@ -1773,7 +1784,7 @@ mod tests { BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] }, ] )) - .clear_signing_pubkey() + .clear_issuer_signing_pubkey() .build() .unwrap(); if let Err(e) = offer.to_string().parse::() { @@ -1828,14 +1839,14 @@ mod tests { } #[test] - fn parses_offer_with_node_id() { + fn parses_offer_with_issuer_id() { let offer = OfferBuilder::new(pubkey(42)).build().unwrap(); if let Err(e) = offer.to_string().parse::() { panic!("error parsing offer: {:?}", e); } let mut tlv_stream = offer.as_tlv_stream(); - tlv_stream.node_id = None; + tlv_stream.issuer_id = None; let mut encoded_offer = Vec::new(); tlv_stream.write(&mut encoded_offer).unwrap(); @@ -1843,7 +1854,7 @@ mod tests { match Offer::try_from(encoded_offer) { Ok(_) => panic!("expected error"), Err(e) => { - assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey)); + assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingIssuerSigningPubkey)); }, } } @@ -1874,6 +1885,8 @@ mod bolt12_tests { fn parses_bech32_encoded_offers() { let offers = [ // Minimal bolt12 offer + "lno1zcss9mk8y3wkklfvevcrszlmu23kfrxh49px20665dqwmn4p72pksese", + // with description (but no amount) "lno1pgx9getnwss8vetrw3hhyuckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg", // for testnet @@ -1918,8 +1931,11 @@ mod bolt12_tests { // ... and with sciddir introduction node "lno1pgx9getnwss8vetrw3hhyucs3yqqqqqqqqqqqqp2qgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqqyqqqqqqqqqqqqqqqqqqqqqqqqqqqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqqgzyg3zyg3zyg3z93pqthvwfzadd7jejes8q9lhc4rvjxd022zv5l44g6qah82ru5rdpnpj", - // ... and with second blinded path via Carol (0x434343...), blinding 020202... - "lno1pgx9getnwss8vetrw3hhyucsl5q5yqeyv5l2cs6y3qqzesrth7mlzrlp3xg7xhulusczm04x6g6nms9trspqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqqsqqqqqqqqqqqqqqqqqqqqqqqqqqpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsqpqg3zyg3zyg3zygz0uc7h32x9s0aecdhxlk075kn046aafpuuyw8f5j652t3vha2yqrsyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsqzqqqqqqqqqqqqqqqqqqqqqqqqqqqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqqyzyg3zyg3zyg3zzcss9mk8y3wkklfvevcrszlmu23kfrxh49px20665dqwmn4p72pksese", + // with no issuer_id and blinded path via Bob (0x424242...), blinding 020202... + "lno1pgx9getnwss8vetrw3hhyucs5ypjgef743p5fzqq9nqxh0ah7y87rzv3ud0eleps9kl2d5348hq2k8qzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgqpqqqqqqqqqqqqqqqqqqqqqqqqqqqzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqqzq3zyg3zyg3zygs", + + //... and with second blinded path via 1x2x3 (direction 1), blinding 020202... + "lno1pgx9getnwss8vetrw3hhyucsl5qj5qeyv5l2cs6y3qqzesrth7mlzrlp3xg7xhulusczm04x6g6nms9trspqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqqsqqqqqqqqqqqqqqqqqqqqqqqqqqpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsqpqg3zyg3zyg3zygpqqqqzqqqqgqqxqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgqqsg3zyg3zyg3zygtzzqhwcuj966ma9n9nqwqtl032xeyv6755yeflt235pmww58egx6rxry", // unknown odd field "lno1pgx9getnwss8vetrw3hhyuckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxfppf5x2mrvdamk7unvvs", @@ -1948,7 +1964,7 @@ mod bolt12_tests { // Malformed: empty assert_eq!( "lno1".parse::(), - Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey)), + Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingIssuerSigningPubkey)), ); // Malformed: truncated at type @@ -2053,7 +2069,7 @@ mod bolt12_tests { Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)), ); - // Malformed: invalid offer_node_id + // Malformed: invalid offer_issuer_id assert_eq!( "lno1pgz5znzfgdz3vggzqvpsxqcrqvpsxqcrqvpsxqcrqvpsxqcrqvpsxqcrqvpsxqcrqvps".parse::(), Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)), @@ -2078,10 +2094,16 @@ mod bolt12_tests { Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingDescription)), ); - // Missing offer_node_id" + // Missing offer_issuer_id assert_eq!( "lno1pgx9getnwss8vetrw3hhyuc".parse::(), - Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey)), + Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingIssuerSigningPubkey)), + ); + + // Second offer_path is empty + assert_eq!( + "lno1pgx9getnwss8vetrw3hhyucsespjgef743p5fzqq9nqxh0ah7y87rzv3ud0eleps9kl2d5348hq2k8qzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgqpqqqqqqqqqqqqqqqqqqqqqqqqqqqzqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqqzq3zyg3zyg3zygszqqqqyqqqqsqqvpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqsq".parse::(), + Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)), ); } } diff --git a/lightning/src/offers/parse.rs b/lightning/src/offers/parse.rs index 8b9f64d8b39..24a78480724 100644 --- a/lightning/src/offers/parse.rs +++ b/lightning/src/offers/parse.rs @@ -135,7 +135,7 @@ pub enum Bolt12ParseError { /// Error when interpreting a TLV stream as a specific type. #[derive(Clone, Debug, PartialEq)] pub enum Bolt12SemanticError { - /// The current [`std::time::SystemTime`] is past the offer or invoice's expiration. + /// The current system time is past the offer or invoice's expiration. AlreadyExpired, /// The provided chain hash does not correspond to a supported chain. UnsupportedChain, @@ -157,12 +157,10 @@ pub enum Bolt12SemanticError { UnexpectedFeatures, /// A required description was not provided. MissingDescription, - /// A signing pubkey was not provided. - MissingSigningPubkey, - /// A signing pubkey was provided but a different one was expected. - InvalidSigningPubkey, - /// A signing pubkey was provided but was not expected. - UnexpectedSigningPubkey, + /// An issuer's signing pubkey was not provided. + MissingIssuerSigningPubkey, + /// An issuer's signing pubkey was provided but was not expected. + UnexpectedIssuerSigningPubkey, /// A quantity was expected but was missing. MissingQuantity, /// An unsupported quantity was provided. @@ -175,8 +173,8 @@ pub enum Bolt12SemanticError { UnexpectedMetadata, /// Payer metadata was expected but was missing. MissingPayerMetadata, - /// A payer id was expected but was missing. - MissingPayerId, + /// A payer signing pubkey was expected but was missing. + MissingPayerSigningPubkey, /// The payment id for a refund or request is already in use. DuplicatePaymentId, /// Blinded paths were expected but were missing. @@ -191,6 +189,10 @@ pub enum Bolt12SemanticError { MissingPaymentHash, /// An invoice payment hash was provided but was not expected. UnexpectedPaymentHash, + /// A signing pubkey was not provided. + MissingSigningPubkey, + /// A signing pubkey was provided but a different one was expected. + InvalidSigningPubkey, /// A signature was expected but was missing. MissingSignature, } diff --git a/lightning/src/offers/payer.rs b/lightning/src/offers/payer.rs index 22180ce5f66..0ec5721dc38 100644 --- a/lightning/src/offers/payer.rs +++ b/lightning/src/offers/payer.rs @@ -16,9 +16,10 @@ use crate::util::ser::WithoutLength; use crate::prelude::*; /// An unpredictable sequence of bytes typically containing information needed to derive -/// [`InvoiceRequest::payer_id`]. +/// [`InvoiceRequest::payer_signing_pubkey`] and [`Refund::payer_signing_pubkey`]. /// -/// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id +/// [`InvoiceRequest::payer_signing_pubkey`]: crate::offers::invoice_request::InvoiceRequest::payer_signing_pubkey +/// [`Refund::payer_signing_pubkey`]: crate::offers::refund::Refund::payer_signing_pubkey #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] pub(super) struct PayerContents(pub Metadata); diff --git a/lightning/src/offers/refund.rs b/lightning/src/offers/refund.rs index c07055c5c10..482c3b6884c 100644 --- a/lightning/src/offers/refund.rs +++ b/lightning/src/offers/refund.rs @@ -150,8 +150,8 @@ pub struct RefundMaybeWithDerivedMetadataBuilder<'a> { } macro_rules! refund_explicit_metadata_builder_methods { () => { - /// Creates a new builder for a refund using the [`Refund::payer_id`] for the public node id to - /// send to if no [`Refund::paths`] are set. Otherwise, it may be a transient pubkey. + /// Creates a new builder for a refund using the `signing_pubkey` for the public node id to send + /// to if no [`Refund::paths`] are set. Otherwise, `signing_pubkey` may be a transient pubkey. /// /// Additionally, sets the required (empty) [`Refund::description`], [`Refund::payer_metadata`], /// and [`Refund::amount_msats`]. @@ -164,7 +164,7 @@ macro_rules! refund_explicit_metadata_builder_methods { () => { /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager /// [`ChannelManager::create_refund_builder`]: crate::ln::channelmanager::ChannelManager::create_refund_builder pub fn new( - metadata: Vec, payer_id: PublicKey, amount_msats: u64 + metadata: Vec, signing_pubkey: PublicKey, amount_msats: u64 ) -> Result { if amount_msats > MAX_VALUE_MSAT { return Err(Bolt12SemanticError::InvalidAmount); @@ -175,7 +175,7 @@ macro_rules! refund_explicit_metadata_builder_methods { () => { refund: RefundContents { payer: PayerContents(metadata), description: String::new(), absolute_expiry: None, issuer: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(), - quantity: None, payer_id, payer_note: None, paths: None, + quantity: None, payer_signing_pubkey: signing_pubkey, payer_note: None, paths: None, }, secp_ctx: None, }) @@ -202,7 +202,7 @@ macro_rules! refund_builder_methods { ( /// [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata /// [`Bolt12Invoice::verify_using_payer_data`]: crate::offers::invoice::Bolt12Invoice::verify_using_payer_data /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey - pub fn deriving_payer_id( + pub fn deriving_signing_pubkey( node_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce, secp_ctx: &'a Secp256k1<$secp_context>, amount_msats: u64, payment_id: PaymentId ) -> Result { @@ -217,7 +217,7 @@ macro_rules! refund_builder_methods { ( refund: RefundContents { payer: PayerContents(metadata), description: String::new(), absolute_expiry: None, issuer: None, chain: None, amount_msats, features: InvoiceRequestFeatures::empty(), - quantity: None, payer_id: node_id, payer_note: None, paths: None, + quantity: None, payer_signing_pubkey: node_id, payer_note: None, paths: None, }, secp_ctx: Some(secp_ctx), }) @@ -231,8 +231,8 @@ macro_rules! refund_builder_methods { ( $return_value } - /// Sets the [`Refund::absolute_expiry`] as seconds since the Unix epoch. Any expiry that has - /// already passed is valid and can be checked for using [`Refund::is_expired`]. + /// Sets the [`Refund::absolute_expiry`] as seconds since the Unix epoch. + #[cfg_attr(feature = "std", doc = "Any expiry that has already passed is valid and can be checked for using [`Refund::is_expired`].")] /// /// Successive calls to this method will override the previous setting. pub fn absolute_expiry($($self_mut)* $self: $self_type, absolute_expiry: Duration) -> $return_type { @@ -249,7 +249,7 @@ macro_rules! refund_builder_methods { ( } /// Adds a blinded path to [`Refund::paths`]. Must include at least one path if only connected - /// by private channels or if [`Refund::payer_id`] is not a public node id. + /// by private channels or if [`Refund::payer_signing_pubkey`] is not a public node id. /// /// Successive calls to this method will add another blinded path. Caller is responsible for not /// adding duplicate paths. @@ -324,7 +324,7 @@ macro_rules! refund_builder_methods { ( metadata.derive_from(iv_bytes, tlv_stream, $self.secp_ctx); metadata = derived_metadata; if let Some(keys) = keys { - $self.refund.payer_id = keys.public_key(); + $self.refund.payer_signing_pubkey = keys.public_key(); } $self.refund.payer.0 = metadata; @@ -434,7 +434,7 @@ pub(super) struct RefundContents { amount_msats: u64, features: InvoiceRequestFeatures, quantity: Option, - payer_id: PublicKey, + payer_signing_pubkey: PublicKey, payer_note: Option, paths: Option>, } @@ -477,9 +477,9 @@ impl Refund { } /// An unpredictable series of bytes, typically containing information about the derivation of - /// [`payer_id`]. + /// [`payer_signing_pubkey`]. /// - /// [`payer_id`]: Self::payer_id + /// [`payer_signing_pubkey`]: Self::payer_signing_pubkey pub fn payer_metadata(&self) -> &[u8] { self.contents.metadata() } @@ -510,8 +510,8 @@ impl Refund { /// transient pubkey. /// /// [`paths`]: Self::paths - pub fn payer_id(&self) -> PublicKey { - self.contents.payer_id() + pub fn payer_signing_pubkey(&self) -> PublicKey { + self.contents.payer_signing_pubkey() } /// Payer provided note to include in the invoice. @@ -545,8 +545,8 @@ macro_rules! respond_with_explicit_signing_pubkey_methods { ($self: ident, $buil /// Creates an [`InvoiceBuilder`] for the refund with the given required fields. /// /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after - /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds - /// where [`std::time::SystemTime`] is not available. + /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. + #[cfg_attr(feature = "std", doc = "Useful for non-`std` builds where [`std::time::SystemTime`] is not available.")] /// /// The caller is expected to remember the preimage of `payment_hash` in order to /// claim a payment for the invoice. @@ -727,8 +727,8 @@ impl RefundContents { /// transient pubkey. /// /// [`paths`]: Self::paths - pub fn payer_id(&self) -> PublicKey { - self.payer_id + pub fn payer_signing_pubkey(&self) -> PublicKey { + self.payer_signing_pubkey } /// Payer provided note to include in the invoice. @@ -752,7 +752,7 @@ impl RefundContents { paths: None, issuer: self.issuer.as_ref(), quantity_max: None, - node_id: None, + issuer_id: None, }; let features = { @@ -765,7 +765,7 @@ impl RefundContents { amount: Some(self.amount_msats), features, quantity: self.quantity, - payer_id: Some(&self.payer_id), + payer_id: Some(&self.payer_signing_pubkey), payer_note: self.payer_note.as_ref(), paths: self.paths.as_ref(), }; @@ -844,7 +844,7 @@ impl TryFrom for RefundContents { OfferTlvStream { chains, metadata, currency, amount: offer_amount, description, features: offer_features, absolute_expiry, paths: offer_paths, issuer, quantity_max, - node_id, + issuer_id, }, InvoiceRequestTlvStream { chain, amount, features, quantity, payer_id, payer_note, paths @@ -887,8 +887,8 @@ impl TryFrom for RefundContents { return Err(Bolt12SemanticError::UnexpectedQuantity); } - if node_id.is_some() { - return Err(Bolt12SemanticError::UnexpectedSigningPubkey); + if issuer_id.is_some() { + return Err(Bolt12SemanticError::UnexpectedIssuerSigningPubkey); } let amount_msats = match amount { @@ -901,14 +901,14 @@ impl TryFrom for RefundContents { let features = features.unwrap_or_else(InvoiceRequestFeatures::empty); - let payer_id = match payer_id { - None => return Err(Bolt12SemanticError::MissingPayerId), + let payer_signing_pubkey = match payer_id { + None => return Err(Bolt12SemanticError::MissingPayerSigningPubkey), Some(payer_id) => payer_id, }; Ok(RefundContents { payer, description, absolute_expiry, issuer, chain, amount_msats, features, quantity, - payer_id, payer_note, paths, + payer_signing_pubkey, payer_note, paths, }) } } @@ -985,7 +985,7 @@ mod tests { assert_eq!(refund.chain(), ChainHash::using_genesis_block(Network::Bitcoin)); assert_eq!(refund.amount_msats(), 1000); assert_eq!(refund.features(), &InvoiceRequestFeatures::empty()); - assert_eq!(refund.payer_id(), payer_pubkey()); + assert_eq!(refund.payer_signing_pubkey(), payer_pubkey()); assert_eq!(refund.payer_note(), None); assert_eq!( @@ -1003,7 +1003,7 @@ mod tests { paths: None, issuer: None, quantity_max: None, - node_id: None, + issuer_id: None, }, InvoiceRequestTlvStreamRef { chain: None, @@ -1040,10 +1040,10 @@ mod tests { let payment_id = PaymentId([1; 32]); let refund = RefundBuilder - ::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id) + ::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id) .unwrap() .build().unwrap(); - assert_eq!(refund.payer_id(), node_id); + assert_eq!(refund.payer_signing_pubkey(), node_id); // Fails verification with altered fields let invoice = refund @@ -1089,7 +1089,7 @@ mod tests { } #[test] - fn builds_refund_with_derived_payer_id() { + fn builds_refund_with_derived_signing_pubkey() { let node_id = payer_pubkey(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); let entropy = FixedEntropy {}; @@ -1106,11 +1106,11 @@ mod tests { ); let refund = RefundBuilder - ::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id) + ::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id) .unwrap() .path(blinded_path) .build().unwrap(); - assert_ne!(refund.payer_id(), node_id); + assert_ne!(refund.payer_signing_pubkey(), node_id); let invoice = refund .respond_with_no_std(payment_paths(), payment_hash(), recipient_pubkey(), now()) @@ -1211,7 +1211,7 @@ mod tests { .build() .unwrap(); let (_, _, invoice_request_tlv_stream) = refund.as_tlv_stream(); - assert_eq!(refund.payer_id(), pubkey(42)); + assert_eq!(refund.payer_signing_pubkey(), pubkey(42)); assert_eq!(refund.paths(), paths.as_slice()); assert_ne!(pubkey(42), pubkey(44)); assert_eq!(invoice_request_tlv_stream.payer_id, Some(&pubkey(42))); @@ -1395,7 +1395,7 @@ mod tests { match Refund::try_from(tlv_stream.to_bytes()) { Ok(_) => panic!("expected error"), Err(e) => { - assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId)); + assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerSigningPubkey)); }, } } @@ -1509,14 +1509,14 @@ mod tests { }, } - let node_id = payer_pubkey(); + let issuer_id = payer_pubkey(); let mut tlv_stream = refund.as_tlv_stream(); - tlv_stream.1.node_id = Some(&node_id); + tlv_stream.1.issuer_id = Some(&issuer_id); match Refund::try_from(tlv_stream.to_bytes()) { Ok(_) => panic!("expected error"), Err(e) => { - assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedSigningPubkey)); + assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedIssuerSigningPubkey)); }, } } diff --git a/lightning/src/offers/signer.rs b/lightning/src/offers/signer.rs index ebab9b07243..d8caa2175fe 100644 --- a/lightning/src/offers/signer.rs +++ b/lightning/src/offers/signer.rs @@ -14,6 +14,7 @@ use bitcoin::hashes::cmp::fixed_time_eq; use bitcoin::hashes::hmac::{Hmac, HmacEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, SecretKey, self}; +use types::payment::PaymentHash; use core::fmt; use crate::ln::channelmanager::PaymentId; use crate::ln::inbound_payment::{ExpandedKey, IV_LEN}; @@ -37,7 +38,13 @@ const WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[3; 16]; const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16]; // HMAC input for a `PaymentId`. The HMAC is used in `OffersContext::OutboundPayment`. -const PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16]; +const OFFER_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16]; +// HMAC input for a `PaymentId`. The HMAC is used in `AsyncPaymentsContext::OutboundPayment`. +#[cfg(async_payments)] +const ASYNC_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[6; 16]; + +// HMAC input for a `PaymentHash`. The HMAC is used in `OffersContext::InboundPayment`. +const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[7; 16]; /// Message metadata which possibly is derived from [`MetadataMaterial`] such that it can be /// verified. @@ -395,21 +402,60 @@ fn hmac_for_message<'a>( Ok(hmac) } -pub(crate) fn hmac_for_payment_id( +pub(crate) fn hmac_for_offer_payment_id( payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey, ) -> Hmac { - const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~"; + hmac_for_payment_id(payment_id, nonce, OFFER_PAYMENT_ID_HMAC_INPUT, expanded_key) +} + +pub(crate) fn verify_offer_payment_id( + payment_id: PaymentId, hmac: Hmac, nonce: Nonce, expanded_key: &ExpandedKey, +) -> Result<(), ()> { + if hmac_for_offer_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } +} + +pub(crate) fn hmac_for_payment_hash( + payment_hash: PaymentHash, nonce: Nonce, expanded_key: &ExpandedKey, +) -> Hmac { + const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment Hash"; let mut hmac = expanded_key.hmac_for_offer(); hmac.input(IV_BYTES); hmac.input(&nonce.0); - hmac.input(PAYMENT_ID_HMAC_INPUT); - hmac.input(&payment_id.0); + hmac.input(PAYMENT_HASH_HMAC_INPUT); + hmac.input(&payment_hash.0); Hmac::from_engine(hmac) } -pub(crate) fn verify_payment_id( +pub(crate) fn verify_payment_hash( + payment_hash: PaymentHash, hmac: Hmac, nonce: Nonce, expanded_key: &ExpandedKey, +) -> Result<(), ()> { + if hmac_for_payment_hash(payment_hash, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } +} + +#[cfg(async_payments)] +pub(crate) fn hmac_for_async_payment_id( + payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey, +) -> Hmac { + hmac_for_payment_id(payment_id, nonce, ASYNC_PAYMENT_ID_HMAC_INPUT, expanded_key) +} + +#[cfg(async_payments)] +pub(crate) fn verify_async_payment_id( payment_id: PaymentId, hmac: Hmac, nonce: Nonce, expanded_key: &ExpandedKey, ) -> Result<(), ()> { - if hmac_for_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } + if hmac_for_async_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) } +} + +fn hmac_for_payment_id( + payment_id: PaymentId, nonce: Nonce, hmac_input: &[u8; 16], expanded_key: &ExpandedKey, +) -> Hmac { + const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~"; + let mut hmac = expanded_key.hmac_for_offer(); + hmac.input(IV_BYTES); + hmac.input(&nonce.0); + hmac.input(hmac_input); + hmac.input(&payment_id.0); + + Hmac::from_engine(hmac) } diff --git a/lightning/src/offers/static_invoice.rs b/lightning/src/offers/static_invoice.rs index 33706f928d8..bf88bd9446c 100644 --- a/lightning/src/offers/static_invoice.rs +++ b/lightning/src/offers/static_invoice.rs @@ -20,12 +20,13 @@ use crate::offers::invoice::{ InvoiceTlvStream, InvoiceTlvStreamRef, }; use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common}; +use crate::offers::invoice_request::InvoiceRequest; use crate::offers::merkle::{ - self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, + self, SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream, }; use crate::offers::nonce::Nonce; use crate::offers::offer::{ - Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity, + Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity, OFFER_TYPES, }; use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage}; use crate::util::ser::{CursorReadable, Iterable, WithoutLength, Writeable, Writer}; @@ -109,8 +110,8 @@ impl<'a> StaticInvoiceBuilder<'a> { return Err(Bolt12SemanticError::MissingPaths); } - let offer_signing_pubkey = - offer.signing_pubkey().ok_or(Bolt12SemanticError::MissingSigningPubkey)?; + let issuer_signing_pubkey = + offer.issuer_signing_pubkey().ok_or(Bolt12SemanticError::MissingIssuerSigningPubkey)?; let keys = offer .verify(nonce, &expanded_key, &secp_ctx) @@ -119,7 +120,7 @@ impl<'a> StaticInvoiceBuilder<'a> { .ok_or(Bolt12SemanticError::MissingSigningPubkey)?; let signing_pubkey = keys.public_key(); - if signing_pubkey != offer_signing_pubkey { + if signing_pubkey != issuer_signing_pubkey { return Err(Bolt12SemanticError::InvalidSigningPubkey); } @@ -240,6 +241,30 @@ macro_rules! invoice_accessors { ($self: ident, $contents: expr) => { pub fn supported_quantity(&$self) -> Quantity { $contents.supported_quantity() } + + /// The public key used by the recipient to sign invoices, from + /// [`Offer::issuer_signing_pubkey`]. + /// + /// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey + pub fn issuer_signing_pubkey(&$self) -> Option { + $contents.issuer_signing_pubkey() + } +} } + +macro_rules! invoice_accessors_signing_pubkey { + ($self: ident, $contents: expr, $invoice_type: ty) => +{ + /// The public key corresponding to the key used to sign the invoice. + /// + /// This will be: + /// - [`Offer::issuer_signing_pubkey`] if it's `Some`, otherwise + /// - the final blinded node id from a [`BlindedMessagePath`] in [`Offer::paths`] if `None`. + /// + /// [`Offer::issuer_signing_pubkey`]: crate::offers::offer::Offer::issuer_signing_pubkey + /// [`Offer::paths`]: crate::offers::offer::Offer::paths + pub fn signing_pubkey(&$self) -> PublicKey { + $contents.signing_pubkey() + } } } impl UnsignedStaticInvoice { @@ -270,7 +295,8 @@ impl UnsignedStaticInvoice { Ok(StaticInvoice { bytes: self.bytes, contents: self.contents, signature }) } - invoice_accessors_common!(self, self.contents, StaticInvoice); + invoice_accessors_common!(self, self.contents, UnsignedStaticInvoice); + invoice_accessors_signing_pubkey!(self, self.contents, UnsignedStaticInvoice); invoice_accessors!(self, self.contents); } @@ -306,12 +332,23 @@ where impl StaticInvoice { invoice_accessors_common!(self, self.contents, StaticInvoice); + invoice_accessors_signing_pubkey!(self, self.contents, StaticInvoice); invoice_accessors!(self, self.contents); /// Signature of the invoice verified using [`StaticInvoice::signing_pubkey`]. pub fn signature(&self) -> Signature { self.signature } + + pub(crate) fn from_same_offer(&self, invreq: &InvoiceRequest) -> bool { + let invoice_offer_tlv_stream = TlvStream::new(&self.bytes) + .range(OFFER_TYPES) + .map(|tlv_record| tlv_record.record_bytes); + let invreq_offer_tlv_stream = TlvStream::new(invreq.bytes()) + .range(OFFER_TYPES) + .map(|tlv_record| tlv_record.record_bytes); + invoice_offer_tlv_stream.eq(invreq_offer_tlv_stream) + } } impl InvoiceContents { @@ -407,6 +444,10 @@ impl InvoiceContents { self.offer.supported_quantity() } + fn issuer_signing_pubkey(&self) -> Option { + self.offer.issuer_signing_pubkey() + } + fn payment_paths(&self) -> &[BlindedPaymentPath] { &self.payment_paths[..] } @@ -696,11 +737,9 @@ mod tests { assert!(invoice.fallbacks().is_empty()); assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty()); - let offer_signing_pubkey = offer.signing_pubkey().unwrap(); + let signing_pubkey = offer.issuer_signing_pubkey().unwrap(); let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes); - assert!( - merkle::verify_signature(&invoice.signature, &message, offer_signing_pubkey).is_ok() - ); + assert!(merkle::verify_signature(&invoice.signature, &message, signing_pubkey).is_ok()); let paths = vec![blinded_path()]; assert_eq!( @@ -717,7 +756,7 @@ mod tests { paths: Some(&paths), issuer: None, quantity_max: None, - node_id: Some(&offer_signing_pubkey), + issuer_id: Some(&signing_pubkey), }, InvoiceTlvStreamRef { paths: Some(Iterable( @@ -730,7 +769,7 @@ mod tests { amount: None, fallbacks: None, features: None, - node_id: Some(&offer_signing_pubkey), + node_id: Some(&signing_pubkey), message_paths: Some(&paths), }, SignatureTlvStreamRef { signature: Some(&invoice.signature()) }, @@ -869,7 +908,7 @@ mod tests { } #[test] - fn fails_build_offer_signing_pubkey() { + fn fails_building_with_missing_issuer_signing_pubkey() { let node_id = recipient_pubkey(); let now = now(); let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); @@ -883,16 +922,15 @@ mod tests { .build() .unwrap(); - // Error if offer signing pubkey is missing. - let mut offer_missing_signing_pubkey = valid_offer.clone(); - let mut offer_tlv_stream = offer_missing_signing_pubkey.as_tlv_stream(); - offer_tlv_stream.node_id.take(); + let mut offer_missing_issuer_id = valid_offer.clone(); + let mut offer_tlv_stream = offer_missing_issuer_id.as_tlv_stream(); + offer_tlv_stream.issuer_id.take(); let mut buffer = Vec::new(); offer_tlv_stream.write(&mut buffer).unwrap(); - offer_missing_signing_pubkey = Offer::try_from(buffer).unwrap(); + offer_missing_issuer_id = Offer::try_from(buffer).unwrap(); if let Err(e) = StaticInvoiceBuilder::for_offer_using_derived_keys( - &offer_missing_signing_pubkey, + &offer_missing_issuer_id, payment_paths(), vec![blinded_path()], now, @@ -900,12 +938,20 @@ mod tests { nonce, &secp_ctx, ) { - assert_eq!(e, Bolt12SemanticError::MissingSigningPubkey); + assert_eq!(e, Bolt12SemanticError::MissingIssuerSigningPubkey); } else { panic!("expected error") } + } + + #[test] + fn fails_building_with_invalid_metadata() { + let now = now(); + let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32])); + let entropy = FixedEntropy {}; + let nonce = Nonce::from_entropy_source(&entropy); + let secp_ctx = Secp256k1::new(); - // Error if the offer's metadata cannot be verified. let offer = OfferBuilder::new(recipient_pubkey()) .path(blinded_path()) .metadata(vec![42; 32]) diff --git a/lightning/src/onion_message/async_payments.rs b/lightning/src/onion_message/async_payments.rs index 89756d9f1f3..cc4ca5edfb0 100644 --- a/lightning/src/onion_message/async_payments.rs +++ b/lightning/src/onion_message/async_payments.rs @@ -9,6 +9,7 @@ //! Message handling for async payments. +use crate::blinded_path::message::AsyncPaymentsContext; use crate::io; use crate::ln::msgs::DecodeError; use crate::onion_message::messenger::{MessageSendInstructions, Responder, ResponseInstruction}; @@ -32,7 +33,7 @@ pub trait AsyncPaymentsMessageHandler { /// Handle a [`ReleaseHeldHtlc`] message. If authentication of the message succeeds, an HTLC /// should be released to the corresponding payee. - fn release_held_htlc(&self, message: ReleaseHeldHtlc); + fn release_held_htlc(&self, message: ReleaseHeldHtlc, context: AsyncPaymentsContext); /// Release any [`AsyncPaymentsMessage`]s that need to be sent. /// @@ -60,18 +61,11 @@ pub enum AsyncPaymentsMessage { /// accompanying this onion message should be used to send a [`ReleaseHeldHtlc`] response, which /// will cause the upstream HTLC to be released. #[derive(Clone, Debug)] -pub struct HeldHtlcAvailable { - /// The secret that will be used by the recipient of this message to release the held HTLC. - pub payment_release_secret: [u8; 32], -} +pub struct HeldHtlcAvailable {} /// Releases the HTLC corresponding to an inbound [`HeldHtlcAvailable`] message. #[derive(Clone, Debug)] -pub struct ReleaseHeldHtlc { - /// Used to release the HTLC held upstream if it matches the corresponding - /// [`HeldHtlcAvailable::payment_release_secret`]. - pub payment_release_secret: [u8; 32], -} +pub struct ReleaseHeldHtlc {} impl OnionMessageContents for ReleaseHeldHtlc { fn tlv_type(&self) -> u64 { @@ -87,13 +81,9 @@ impl OnionMessageContents for ReleaseHeldHtlc { } } -impl_writeable_tlv_based!(HeldHtlcAvailable, { - (0, payment_release_secret, required), -}); +impl_writeable_tlv_based!(HeldHtlcAvailable, {}); -impl_writeable_tlv_based!(ReleaseHeldHtlc, { - (0, payment_release_secret, required), -}); +impl_writeable_tlv_based!(ReleaseHeldHtlc, {}); impl AsyncPaymentsMessage { /// Returns whether `tlv_type` corresponds to a TLV record for async payment messages. diff --git a/lightning/src/onion_message/functional_tests.rs b/lightning/src/onion_message/functional_tests.rs index 56c54005739..ef733b0893c 100644 --- a/lightning/src/onion_message/functional_tests.rs +++ b/lightning/src/onion_message/functional_tests.rs @@ -10,7 +10,7 @@ //! Onion message testing and test utilities live here. use crate::blinded_path::EmptyNodeIdLookUp; -use crate::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext}; +use crate::blinded_path::message::{AsyncPaymentsContext, BlindedMessagePath, MessageForwardNode, MessageContext, OffersContext}; use crate::events::{Event, EventsProvider}; use crate::ln::features::{ChannelFeatures, InitFeatures}; use crate::ln::msgs::{self, DecodeError, OnionMessageHandler}; @@ -87,7 +87,7 @@ impl AsyncPaymentsMessageHandler for TestAsyncPaymentsMessageHandler { ) -> Option<(ReleaseHeldHtlc, ResponseInstruction)> { None } - fn release_held_htlc(&self, _message: ReleaseHeldHtlc) {} + fn release_held_htlc(&self, _message: ReleaseHeldHtlc, _context: AsyncPaymentsContext) {} } #[derive(Clone, Debug, PartialEq)] @@ -297,13 +297,13 @@ fn connect_peers(node_a: &MessengerNode, node_b: &MessengerNode) { let mut features = InitFeatures::empty(); features.set_onion_messages_optional(); let init_msg = msgs::Init { features, networks: None, remote_network_address: None }; - node_a.messenger.peer_connected(&node_b.node_id, &init_msg.clone(), true).unwrap(); - node_b.messenger.peer_connected(&node_a.node_id, &init_msg.clone(), false).unwrap(); + node_a.messenger.peer_connected(node_b.node_id, &init_msg.clone(), true).unwrap(); + node_b.messenger.peer_connected(node_a.node_id, &init_msg.clone(), false).unwrap(); } fn disconnect_peers(node_a: &MessengerNode, node_b: &MessengerNode) { - node_a.messenger.peer_disconnected(&node_b.node_id); - node_b.messenger.peer_disconnected(&node_a.node_id); + node_a.messenger.peer_disconnected(node_b.node_id); + node_b.messenger.peer_disconnected(node_a.node_id); } fn release_events(node: &MessengerNode) -> Vec { @@ -335,7 +335,7 @@ fn pass_along_path(path: &Vec) { assert_eq!(msgs.len(), 1); msgs[0].clone() }; - node.messenger.handle_onion_message(&prev_node.node_id, &onion_msg); + node.messenger.handle_onion_message(prev_node.node_id, &onion_msg); prev_node = node; } } @@ -894,18 +894,18 @@ fn spec_test_vector() { // which is why the asserted strings differ slightly from the spec. assert_eq!(sender_to_alice_om.encode(), >::from_hex("031195a8046dcbb8e17034bca630065e7a0982e4e36f6f7e5a8d4554e4846fcd9905560002531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33793b828776d70aabbd8cef1a5b52d5a397ae1a20f20435ff6057cd8be339d5aee226660ef73b64afa45dbf2e6e8e26eb96a259b2db5aeecda1ce2e768bbc35d389d7f320ca3d2bd14e2689bef2f5ac0307eaaabc1924eb972c1563d4646ae131accd39da766257ed35ea36e4222527d1db4fa7b2000aab9eafcceed45e28b5560312d4e2299bd8d1e7fe27d10925966c28d497aec400b4630485e82efbabc00550996bdad5d6a9a8c75952f126d14ad2cff91e16198691a7ef2937de83209285f1fb90944b4e46bca7c856a9ce3da10cdf2a7d00dc2bf4f114bc4d3ed67b91cbde558ce9af86dc81fbdc37f8e301b29e23c1466659c62bdbf8cff5d4c20f0fb0851ec72f5e9385dd40fdd2e3ed67ca4517117825665e50a3e26f73c66998daf18e418e8aef9ce2d20da33c3629db2933640e03e7b44c2edf49e9b482db7b475cfd4c617ae1d46d5c24d697846f9f08561eac2b065f9b382501f6eabf07343ed6c602f61eab99cdb52adf63fd44a8db2d3016387ea708fc1c08591e19b4d9984ebe31edbd684c2ea86526dd8c7732b1d8d9117511dc1b643976d356258fce8313b1cb92682f41ab72dedd766f06de375f9edacbcd0ca8c99b865ea2b7952318ea1fd20775a28028b5cf59dece5de14f615b8df254eee63493a5111ea987224bea006d8f1b60d565eef06ac0da194dba2a6d02e79b2f2f34e9ca6e1984a507319d86e9d4fcaeea41b4b9144e0b1826304d4cc1da61cfc5f8b9850697df8adc5e9d6f3acb3219b02764b4909f2b2b22e799fd66c383414a84a7d791b899d4aa663770009eb122f90282c8cb9cda16aba6897edcf9b32951d0080c0f52be3ca011fbec3fb16423deb47744645c3b05fdbd932edf54ba6efd26e65340a8e9b1d1216582e1b30d64524f8ca2d6c5ba63a38f7120a3ed71bed8960bcac2feee2dd41c90be48e3c11ec518eb3d872779e4765a6cc28c6b0fa71ab57ced73ae963cc630edae4258cba2bf25821a6ae049fec2fca28b5dd1bb004d92924b65701b06dcf37f0ccd147a13a03f9bc0f98b7d78fe9058089756931e2cd0e0ed92ec6759d07b248069526c67e9e6ce095118fd3501ba0f858ef030b76c6f6beb11a09317b5ad25343f4b31aef02bc555951bc7791c2c289ecf94d5544dcd6ad3021ed8e8e3db34b2a73e1eedb57b578b068a5401836d6e382110b73690a94328c404af25e85a8d6b808893d1b71af6a31fadd8a8cc6e31ecc0d9ff7e6b91fd03c274a5c1f1ccd25b61150220a3fddb04c91012f5f7a83a5c90deb2470089d6e38cd5914b9c946eca6e9d31bbf8667d36cf87effc3f3ff283c21dd4137bd569fe7cf758feac94053e4baf7338bb592c8b7c291667fadf4a9bf9a2a154a18f612cbc7f851b3f8f2070e0a9d180622ee4f8e81b0ab250d504cef24116a3ff188cc829fcd8610b56343569e8dc997629410d1967ca9dd1d27eec5e01e4375aad16c46faba268524b154850d0d6fe3a76af2c6aa3e97647c51036049ac565370028d6a439a2672b6face56e1b171496c0722cfa22d9da631be359661617c5d5a2d286c5e19db9452c1e21a0107b6400debda2decb0c838f342dd017cdb2dccdf1fe97e3df3f881856b546997a3fed9e279c720145101567dd56be21688fed66bf9759e432a9aa89cbbd225d13cdea4ca05f7a45cfb6a682a3d5b1e18f7e6cf934fae5098108bae9058d05c3387a01d8d02a656d2bfff67e9f46b2d8a6aac28129e52efddf6e552214c3f8a45bc7a912cca9a7fec1d7d06412c6972cb9e3dc518983f56530b8bffe7f92c4b6eb47d4aef59fb513c4653a42de61bc17ad7728e7fc7590ff05a9e991de03f023d0aaf8688ed6170def5091c66576a424ac1cb").unwrap()); let sender_dummy_node_id = PublicKey::from_slice(&[2; 33]).unwrap(); - nodes[0].messenger.handle_onion_message(&sender_dummy_node_id, &sender_to_alice_om); + nodes[0].messenger.handle_onion_message(sender_dummy_node_id, &sender_to_alice_om); let alice_to_bob_om = nodes[0].messenger.next_onion_message_for_peer(nodes[1].node_id).unwrap(); assert_eq!(alice_to_bob_om.encode(), >::from_hex("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f05560002536d53f93796cad550b6c68662dca41f7e8c221c31022c64dd1a627b2df3982b25eac261e88369cfc66e1e3b6d9829cb3dcd707046e68a7796065202a7904811bf2608c5611cf74c9eb5371c7eb1a4428bb39a041493e2a568ddb0b2482a6cc6711bc6116cef144ebf988073cb18d9dd4ce2d3aa9de91a7dc6d7c6f11a852024626e66b41ba1158055505dff9cb15aa51099f315564d9ee3ed6349665dc3e209eedf9b5805ee4f69d315df44c80e63d0e2efbdab60ec96f44a3447c6a6ddb1efb6aa4e072bde1dab974081646bfddf3b02daa2b83847d74dd336465e76e9b8fecc2b0414045eeedfc39939088a76820177dd1103c99939e659beb07197bab9f714b30ba8dc83738e9a6553a57888aaeda156c68933a2f4ff35e3f81135076b944ed9856acbfee9c61299a5d1763eadd14bf5eaf71304c8e165e590d7ecbcd25f1650bf5b6c2ad1823b2dc9145e168974ecf6a2273c94decff76d94bc6708007a17f22262d63033c184d0166c14f41b225a956271947aae6ce65890ed8f0d09c6ffe05ec02ee8b9de69d7077a0c5adeb813aabcc1ba8975b73ab06ddea5f4db3c23a1de831602de2b83f990d4133871a1a81e53f86393e6a7c3a7b73f0c099fa72afe26c3027bb9412338a19303bd6e6591c04fb4cde9b832b5f41ae199301ea8c303b5cef3aca599454273565de40e1148156d1f97c1aa9e58459ab318304075e034f5b7899c12587b86776a18a1da96b7bcdc22864fccc4c41538ebce92a6f054d53bf46770273a70e75fe0155cd6d2f2e937465b0825ce3123b8c206fac4c30478fa0f08a97ade7216dce11626401374993213636e93545a31f500562130f2feb04089661ad8c34d5a4cbd2e4e426f37cb094c786198a220a2646ecadc38c04c29ee67b19d662c209a7b30bfecc7fe8bf7d274de0605ee5df4db490f6d32234f6af639d3fce38a2801bcf8d51e9c090a6c6932355a83848129a378095b34e71cb8f51152dc035a4fe8e802fec8de221a02ba5afd6765ce570bef912f87357936ea0b90cb2990f56035e89539ec66e8dbd6ed50835158614096990e019c3eba3d7dd6a77147641c6145e8b17552cd5cf7cd163dd40b9eaeba8c78e03a2cd8c0b7997d6f56d35f38983a202b4eb8a54e14945c4de1a6dde46167e11708b7a5ff5cb9c0f7fc12fae49a012aa90bb1995c038130b749c48e6f1ffb732e92086def42af10fbc460d94abeb7b2fa744a5e9a491d62a08452be8cf2fdef573deedc1fe97098bce889f98200b26f9bb99da9aceddda6d793d8e0e44a2601ef4590cfbb5c3d0197aac691e3d31c20fd8e38764962ca34dabeb85df28feabaf6255d4d0df3d814455186a84423182caa87f9673df770432ad8fdfe78d4888632d460d36d2719e8fa8e4b4ca10d817c5d6bc44a8b2affab8c2ba53b8bf4994d63286c2fad6be04c28661162fa1a67065ecda8ba8c13aee4a8039f4f0110e0c0da2366f178d8903e19136dad6df9d8693ce71f3a270f9941de2a93d9b67bc516207ac1687bf6e00b29723c42c7d9c90df9d5e599dbeb7b73add0a6a2b7aba82f98ac93cb6e60494040445229f983a81c34f7f686d166dfc98ec23a6318d4a02a311ac28d655ea4e0f9c3014984f31e621ef003e98c373561d9040893feece2e0fa6cd2dd565e6fbb2773a2407cb2c3273c306cf71f427f2e551c4092e067cf9869f31ac7c6c80dd52d4f85be57a891a41e34be0d564e39b4af6f46b85339254a58b205fb7e10e7d0470ee73622493f28c08962118c23a1198467e72c4ae1cd482144b419247a5895975ea90d135e2a46ef7e5794a1551a447ff0a0d299b66a7f565cd86531f5e7af5408d85d877ce95b1df12b88b7d5954903a5296325ba478ba1e1a9d1f30a2d5052b2e2889bbd64f72c72bc71d8817288a2").unwrap()); - nodes[1].messenger.handle_onion_message(&nodes[0].node_id, &alice_to_bob_om); + nodes[1].messenger.handle_onion_message(nodes[0].node_id, &alice_to_bob_om); let bob_to_carol_om = nodes[1].messenger.next_onion_message_for_peer(nodes[2].node_id).unwrap(); assert_eq!(bob_to_carol_om.encode(), >::from_hex("02b684babfd400c8dd48b367e9754b8021a3594a34dc94d7101776c7f6a86d0582055600029a77e8523162efa1f4208f4f2050cd5c386ddb6ce6d36235ea569d217ec52209fb85fdf7dbc4786c373eebdba0ddc184cfbe6da624f610e93f62c70f2c56be1090b926359969f040f932c03f53974db5656233bd60af375517d4323002937d784c2c88a564bcefe5c33d3fc21c26d94dfacab85e2e19685fd2ff4c543650958524439b6da68779459aee5ffc9dc543339acec73ff43be4c44ddcbe1c11d50e2411a67056ba9db7939d780f5a86123fdd3abd6f075f7a1d78ab7daf3a82798b7ec1e9f1345bc0d1e935098497067e2ae5a51ece396fcb3bb30871ad73aee51b2418b39f00c8e8e22be4a24f4b624e09cb0414dd46239de31c7be035f71e8da4f5a94d15b44061f46414d3f355069b5c5b874ba56704eb126148a22ec873407fe118972127e63ff80e682e410f297f23841777cec0517e933eaf49d7e34bd203266b42081b3a5193b51ccd34b41342bc67cf73523b741f5c012ba2572e9dda15fbe131a6ac2ff24dc2a7622d58b9f3553092cfae7fae3c8864d95f97aa49ec8edeff5d9f5782471160ee412d82ff6767030fc63eec6a93219a108cd41433834b26676a39846a944998796c79cd1cc460531b8ded659cedfd8aecefd91944f00476f1496daafb4ea6af3feacac1390ea510709783c2aa81a29de27f8959f6284f4684102b17815667cbb0645396ac7d542b878d90c42a1f7f00c4c4eedb2a22a219f38afadb4f1f562b6e000a94e75cc38f535b43a3c0384ccef127fde254a9033a317701c710b2b881065723486e3f4d3eea5e12f374a41565fe43fa137c1a252c2153dde055bb343344c65ad0529010ece29bbd405effbebfe3ba21382b94a60ac1a5ffa03f521792a67b30773cb42e862a8a02a8bbd41b842e115969c87d1ff1f8c7b5726b9f20772dd57fe6e4ea41f959a2a673ffad8e2f2a472c4c8564f3a5a47568dd75294b1c7180c500f7392a7da231b1fe9e525ea2d7251afe9ca52a17fe54a116cb57baca4f55b9b6de915924d644cba9dade4ccc01939d7935749c008bafc6d3ad01cd72341ce5ddf7a5d7d21cf0465ab7a3233433aef21f9acf2bfcdc5a8cc003adc4d82ac9d72b36eb74e05c9aa6ccf439ac92e6b84a3191f0764dd2a2e0b4cc3baa08782b232ad6ecd3ca6029bc08cc094aef3aebddcaddc30070cb6023a689641de86cfc6341c8817215a4650f844cd2ca60f2f10c6e44cfc5f23912684d4457bf4f599879d30b79bf12ef1ab8d34dddc15672b82e56169d4c770f0a2a7a960b1e8790773f5ff7fce92219808f16d061cc85e053971213676d28fb48925e9232b66533dbd938458eb2cc8358159df7a2a2e4cf87500ede2afb8ce963a845b98978edf26a6948d4932a6b95d022004556d25515fe158092ce9a913b4b4a493281393ca731e8d8e5a3449b9d888fc4e73ffcbb9c6d6d66e88e03cf6e81a0496ede6e4e4172b08c000601993af38f80c7f68c9d5fff9e0e215cff088285bf039ca731744efcb7825a272ca724517736b4890f47e306b200aa2543c363e2c9090bcf3cf56b5b86868a62471c7123a41740392fc1d5ab28da18dca66618e9af7b42b62b23aba907779e73ca03ec60e6ab9e0484b9cae6578e0fddb6386cb3468506bf6420298bf4a690947ab582255551d82487f271101c72e19e54872ab47eae144db66bc2f8194a666a5daec08d12822cb83a61946234f2dfdbd6ca7d8763e6818adee7b401fcdb1ac42f9df1ac5cc5ac131f2869013c8d6cd29d4c4e3d05bccd34ca83366d616296acf854fa05149bfd763a25b9938e96826a037fdcb85545439c76df6beed3bdbd01458f9cf984997cc4f0a7ac3cc3f5e1eeb59c09cadcf5a537f16e444149c8f17d4bdaef16c9fbabc5ef06eb0f0bf3a07a1beddfeacdaf1df5582d6dbd6bb808d6ab31bc22e5d7").unwrap()); - nodes[2].messenger.handle_onion_message(&nodes[1].node_id, &bob_to_carol_om); + nodes[2].messenger.handle_onion_message(nodes[1].node_id, &bob_to_carol_om); let carol_to_dave_om = nodes[2].messenger.next_onion_message_for_peer(nodes[3].node_id).unwrap(); assert_eq!(carol_to_dave_om.encode(), >::from_hex("025aaca62db7ce6b46386206ef9930daa32e979a35cb185a41cb951aa7d254b03c055600025550b2910294fa73bda99b9de9c851be9cbb481e23194a1743033630efba546b86e7d838d0f6e9cc0ed088dbf6889f0dceca3bfc745bd77d013a31311fa932a8bf1d28387d9ff521eabc651dee8f861fed609a68551145a451f017ec44978addeee97a423c08445531da488fd1ddc998e9cdbfcea59517b53fbf1833f0bbe6188dba6ca773a247220ec934010daca9cc185e1ceb136803469baac799e27a0d82abe53dc48a06a55d1f643885cc7894677dd20a4e4152577d1ba74b870b9279f065f9b340cedb3ca13b7df218e853e10ccd1b59c42a2acf93f489e170ee4373d30ab158b60fc20d3ba73a1f8c750951d69fb5b9321b968ddc8114936412346aff802df65516e1c09c51ef19849ff36c0199fd88c8bec301a30fef0c7cb497901c038611303f64e4174b5daf42832aa5586b84d2c9b95f382f4269a5d1bd4be898618dc78dfd451170f72ca16decac5b03e60702112e439cadd104fb3bbb3d5023c9b80823fdcd0a212a7e1aaa6eeb027adc7f8b3723031d135a09a979a4802788bb7861c6cc85501fb91137768b70aeab309b27b885686604ffc387004ac4f8c44b101c39bc0597ef7fd957f53fc5051f534b10eb3852100962b5e58254e5558689913c26ad6072ea41f5c5db10077cfc91101d4ae393be274c74297da5cc381cd88d54753aaa7df74b2f9da8d88a72bc9218fcd1f19e4ff4aace182312b9509c5175b6988f044c5756d232af02a451a02ca752f3c52747773acff6fd07d2032e6ce562a2c42105d106eba02d0b1904182cdc8c74875b082d4989d3a7e9f0e73de7c75d357f4af976c28c0b206c5e8123fc2391d078592d0d5ff686fd245c0a2de2e535b7cca99c0a37d432a8657393a9e3ca53eec1692159046ba52cb9bc97107349d8673f74cbc97e231f1108005c8d03e24ca813cea2294b39a7a493bcc062708f1f6cf0074e387e7d50e0666ce784ef4d31cb860f6cad767438d9ea5156ff0ae86e029e0247bf94df75ee0cda4f2006061455cb2eaff513d558863ae334cef7a3d45f55e7cc13153c6719e9901c1d4db6c03f643b69ea4860690305651794284d9e61eb848ccdf5a77794d376f0af62e46d4835acce6fd9eef5df73ebb8ea3bb48629766967f446e744ecc57ff3642c4aa1ccee9a2f72d5caa75fa05787d08b79408fce792485fdecdc25df34820fb061275d70b84ece540b0fc47b2453612be34f2b78133a64e812598fbe225fd85415f8ffe5340ce955b5fd9d67dd88c1c531dde298ed25f96df271558c812c26fa386966c76f03a6ebccbca49ac955916929bd42e134f982dde03f924c464be5fd1ba44f8dc4c3cbc8162755fd1d8f7dc044b15b1a796c53df7d8769bb167b2045b49cc71e08908796c92c16a235717cabc4bb9f60f8f66ff4fff1f9836388a99583acebdff4a7fb20f48eedcd1f4bdcc06ec8b48e35307df51d9bc81d38a94992dd135b30079e1f592da6e98dff496cb1a7776460a26b06395b176f585636ebdf7eab692b227a31d6979f5a6141292698e91346b6c806b90c7c6971e481559cae92ee8f4136f2226861f5c39ddd29bbdb118a35dece03f49a96804caea79a3dacfbf09d65f2611b5622de51d98e18151acb3bb84c09caaa0cc80edfa743a4679f37d6167618ce99e73362fa6f213409931762618a61f1738c071bba5afc1db24fe94afb70c40d731908ab9a505f76f57a7d40e708fd3df0efc5b7cbb2a7b75cd23449e09684a2f0e2bfa0d6176c35f96fe94d92fc9fa4103972781f81cb6e8df7dbeb0fc529c600d768bed3f08828b773d284f69e9a203459d88c12d6df7a75be2455fec128f07a497a2b2bf626cc6272d0419ca663e9dc66b8224227eb796f0246dcae9c5b0b6cfdbbd40c3245a610481c92047c968c9fc92c04b89cc41a0c15355a8f").unwrap()); // Dave handles the onion message but he'll log that he errored while decoding the hop data // because he sees it as an empty onion message (the only contents of the sender's OM is "hello" // with TLV type 1, which Dave ignores because (1) it's odd and he can't understand it and (2) LDK // only attempts to parse custom OM TLVs with type > 64). - nodes[3].messenger.handle_onion_message(&nodes[2].node_id, &carol_to_dave_om); + nodes[3].messenger.handle_onion_message(nodes[2].node_id, &carol_to_dave_om); } diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index f40a59f2c0c..19e24ac818b 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -151,7 +151,7 @@ for OnionMessenger where /// # use lightning::blinded_path::message::{BlindedMessagePath, MessageForwardNode, MessageContext}; /// # use lightning::sign::{EntropySource, KeysManager}; /// # use lightning::ln::peer_handler::IgnoringMessageHandler; -/// # use lightning::onion_message::messenger::{Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger}; +/// # use lightning::onion_message::messenger::{BlindedPathType, Destination, MessageRouter, MessageSendInstructions, OnionMessagePath, OnionMessenger}; /// # use lightning::onion_message::packet::OnionMessageContents; /// # use lightning::util::logger::{Logger, Record}; /// # use lightning::util::ser::{Writeable, Writer}; @@ -175,7 +175,7 @@ for OnionMessenger where /// # }) /// # } /// # fn create_blinded_paths( -/// # &self, _recipient: PublicKey, _context: MessageContext, _peers: Vec, _secp_ctx: &Secp256k1 +/// # &self, _recipient: PublicKey, _context: MessageContext, _blinded_path: BlindedPathType, _peers: Vec, _secp_ctx: &Secp256k1 /// # ) -> Result, ()> { /// # unreachable!() /// # } @@ -432,6 +432,14 @@ pub enum MessageSendInstructions { }, } +/// Represents the types of [`BlindedMessagePath`] that can be created. +pub enum BlindedPathType { + /// Whether the created [`BlindedMessagePath`]s are compact. + Compact, + /// Whether the created [`BlindedMessagePath`]s are full-length. + Full, +} + /// A trait defining behavior for routing an [`OnionMessage`]. pub trait MessageRouter { /// Returns a route for sending an [`OnionMessage`] to the given [`Destination`]. @@ -441,14 +449,9 @@ pub trait MessageRouter { /// Creates [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are assumed to /// be direct peers with the `recipient`. - fn create_blinded_paths< - T: secp256k1::Signing + secp256k1::Verification - >( - &self, recipient: PublicKey, context: MessageContext, peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()>; - - /// Creates compact [`BlindedMessagePath`]s to the `recipient` node. The nodes in `peers` are - /// assumed to be direct peers with the `recipient`. + /// + /// # Note of compact blinded path: + /// User can decide to create compact blinded path by specifying the appropirate [`BlindedPathType`]. /// /// Compact blinded paths use short channel ids instead of pubkeys for a smaller serialization, /// which is beneficial when a QR code is used to transport the data. The SCID is passed using @@ -457,21 +460,12 @@ pub trait MessageRouter { /// Implementations using additional intermediate nodes are responsible for using a /// [`MessageForwardNode`] with `Some` short channel id, if possible. Similarly, implementations /// should call [`BlindedMessagePath::use_compact_introduction_node`]. - /// - /// The provided implementation simply delegates to [`MessageRouter::create_blinded_paths`], - /// ignoring the short channel ids. - fn create_compact_blinded_paths< + fn create_blinded_paths< T: secp256k1::Signing + secp256k1::Verification >( - &self, recipient: PublicKey, context: MessageContext, + &self, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()> { - let peers = peers - .into_iter() - .map(|MessageForwardNode { node_id, short_channel_id: _ }| node_id) - .collect(); - self.create_blinded_paths(recipient, context, peers, secp_ctx) - } + ) -> Result, ()>; } /// A [`MessageRouter`] that can only route to a directly connected [`Destination`]. @@ -505,8 +499,8 @@ where I: ExactSizeIterator, T: secp256k1::Signing + secp256k1::Verification >( - network_graph: &G, recipient: PublicKey, context: MessageContext, peers: I, - entropy_source: &ES, secp_ctx: &Secp256k1, compact_paths: bool, + network_graph: &G, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, + peers: I, entropy_source: &ES, secp_ctx: &Secp256k1 ) -> Result, ()> { // Limit the number of blinded paths that are computed. const MAX_PATHS: usize = 3; @@ -562,10 +556,13 @@ where }, }?; - if compact_paths { - for path in &mut paths { - path.use_compact_introduction_node(&network_graph); + match blinded_path { + BlindedPathType::Compact => { + for path in &mut paths { + path.use_compact_introduction_node(&network_graph); + } } + BlindedPathType::Full => {} } Ok(paths) @@ -607,22 +604,10 @@ where pub(crate) fn create_blinded_paths< T: secp256k1::Signing + secp256k1::Verification >( - network_graph: &G, recipient: PublicKey, context: MessageContext, - peers: Vec, entropy_source: &ES, secp_ctx: &Secp256k1, - ) -> Result, ()> { - let peers = peers - .into_iter() - .map(|node_id| MessageForwardNode { node_id, short_channel_id: None }); - Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, false) - } - - pub(crate) fn create_compact_blinded_paths< - T: secp256k1::Signing + secp256k1::Verification - >( - network_graph: &G, recipient: PublicKey, context: MessageContext, + network_graph: &G, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, peers: Vec, entropy_source: &ES, secp_ctx: &Secp256k1, ) -> Result, ()> { - Self::create_blinded_paths_from_iter(network_graph, recipient, context, peers.into_iter(), entropy_source, secp_ctx, true) + Self::create_blinded_paths_from_iter(network_graph, recipient, context, blinded_path, peers.into_iter(), entropy_source, secp_ctx) } } @@ -640,19 +625,11 @@ where fn create_blinded_paths< T: secp256k1::Signing + secp256k1::Verification >( - &self, recipient: PublicKey, context: MessageContext, peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()> { - Self::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx) - } - - fn create_compact_blinded_paths< - T: secp256k1::Signing + secp256k1::Verification - >( - &self, recipient: PublicKey, context: MessageContext, peers: Vec, secp_ctx: &Secp256k1, + &self, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, + peers: Vec, secp_ctx: &Secp256k1, ) -> Result, ()> { - Self::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx) + Self::create_blinded_paths(&self.network_graph, recipient, context, blinded_path, peers, &self.entropy_source, secp_ctx) } - } /// A path for sending an [`OnionMessage`]. @@ -979,6 +956,10 @@ where (ParsedOnionMessageContents::Offers(_), Some(MessageContext::Offers(_))) => { Ok(PeeledOnion::Receive(message, context, reply_path)) } + #[cfg(async_payments)] + (ParsedOnionMessageContents::AsyncPayments(_), Some(MessageContext::AsyncPayments(_))) => { + Ok(PeeledOnion::Receive(message, context, reply_path)) + } (ParsedOnionMessageContents::Custom(_), Some(MessageContext::Custom(_))) => { Ok(PeeledOnion::Receive(message, context, reply_path)) } @@ -1243,11 +1224,16 @@ where let peers = self.message_recipients.lock().unwrap() .iter() .filter(|(_, peer)| matches!(peer, OnionMessageRecipient::ConnectedPeer(_))) - .map(|(node_id, _ )| *node_id) + .map(|(node_id, _ )| { + MessageForwardNode { + node_id: *node_id, + short_channel_id: None, + } + }) .collect::>(); self.message_router - .create_blinded_paths(recipient, context, peers, secp_ctx) + .create_blinded_paths(recipient, context, BlindedPathType::Full, peers, secp_ctx) .and_then(|paths| paths.into_iter().next().ok_or(())) .map_err(|_| SendError::PathNotFound) } @@ -1572,8 +1558,8 @@ where APH::Target: AsyncPaymentsMessageHandler, CMH::Target: CustomOnionMessageHandler, { - fn handle_onion_message(&self, peer_node_id: &PublicKey, msg: &OnionMessage) { - let logger = WithContext::from(&self.logger, Some(*peer_node_id), None, None); + fn handle_onion_message(&self, peer_node_id: PublicKey, msg: &OnionMessage) { + let logger = WithContext::from(&self.logger, Some(peer_node_id), None, None); match self.peel_onion_message(msg) { Ok(PeeledOnion::Receive(message, context, reply_path)) => { log_trace!( @@ -1587,8 +1573,8 @@ where let context = match context { None => None, Some(MessageContext::Offers(context)) => Some(context), - Some(MessageContext::Custom(_)) => { - debug_assert!(false, "Shouldn't have triggered this case."); + _ => { + debug_assert!(false, "Checked in peel_onion_message"); return } }; @@ -1608,14 +1594,22 @@ where }, #[cfg(async_payments)] ParsedOnionMessageContents::AsyncPayments(AsyncPaymentsMessage::ReleaseHeldHtlc(msg)) => { - self.async_payments_handler.release_held_htlc(msg); + let context = match context { + Some(MessageContext::AsyncPayments(context)) => context, + Some(_) => { + debug_assert!(false, "Checked in peel_onion_message"); + return + }, + None => return, + }; + self.async_payments_handler.release_held_htlc(msg, context); }, ParsedOnionMessageContents::Custom(msg) => { let context = match context { None => None, Some(MessageContext::Custom(data)) => Some(data), - Some(MessageContext::Offers(_)) => { - debug_assert!(false, "Shouldn't have triggered this case."); + _ => { + debug_assert!(false, "Checked in peel_onion_message"); return } }; @@ -1681,29 +1675,29 @@ where } } - fn peer_connected(&self, their_node_id: &PublicKey, init: &msgs::Init, _inbound: bool) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: PublicKey, init: &msgs::Init, _inbound: bool) -> Result<(), ()> { if init.features.supports_onion_messages() { self.message_recipients.lock().unwrap() - .entry(*their_node_id) + .entry(their_node_id) .or_insert_with(|| OnionMessageRecipient::ConnectedPeer(VecDeque::new())) .mark_connected(); if self.intercept_messages_for_offline_peers { let mut pending_peer_connected_events = self.pending_peer_connected_events.lock().unwrap(); pending_peer_connected_events.push( - Event::OnionMessagePeerConnected { peer_node_id: *their_node_id } + Event::OnionMessagePeerConnected { peer_node_id: their_node_id } ); self.event_notifier.notify(); } } else { - self.message_recipients.lock().unwrap().remove(their_node_id); + self.message_recipients.lock().unwrap().remove(&their_node_id); } Ok(()) } - fn peer_disconnected(&self, their_node_id: &PublicKey) { - match self.message_recipients.lock().unwrap().remove(their_node_id) { + fn peer_disconnected(&self, their_node_id: PublicKey) { + match self.message_recipients.lock().unwrap().remove(&their_node_id) { Some(OnionMessageRecipient::ConnectedPeer(..)) => {}, Some(_) => debug_assert!(false), None => {}, @@ -1736,7 +1730,7 @@ where features } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { let mut features = InitFeatures::empty(); features.set_onion_messages_optional(); features @@ -1753,6 +1747,14 @@ where ); } + #[cfg(async_payments)] { + for (message, instructions) in self.async_payments_handler.release_pending_messages() { + let _ = self.send_onion_message_internal( + message, instructions, format_args!("when sending AsyncPaymentsMessage") + ); + } + } + // Enqueue any initiating `CustomMessage`s to send. for (message, instructions) in self.custom_handler.release_pending_custom_messages() { let _ = self.send_onion_message_internal( diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index f1bc73110bf..afff249f7c5 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -183,7 +183,7 @@ pub struct NetworkGraph where L::Target: Logger { // // NOTE: In the following `removed_*` maps, we use seconds since UNIX epoch to track time instead // of `std::time::Instant`s for a few reasons: - // * We want it to be possible to do tracking in no-std environments where we can compare + // * We want it to be possible to do tracking in non-`std` environments where we can compare // a provided current UNIX timestamp with the time at which we started tracking. // * In the future, if we decide to persist these maps, they will already be serializable. // * Although we lose out on the platform's monotonic clock, the system clock in a std @@ -484,19 +484,19 @@ pub fn verify_channel_announcement(msg: &ChannelAnnouncement, s impl>, U: Deref, L: Deref> RoutingMessageHandler for P2PGossipSync where U::Target: UtxoLookup, L::Target: Logger { - fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result { + fn handle_node_announcement(&self, _their_node_id: Option, msg: &msgs::NodeAnnouncement) -> Result { self.network_graph.update_node_from_announcement(msg)?; Ok(msg.contents.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY && msg.contents.excess_address_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY && msg.contents.excess_data.len() + msg.contents.excess_address_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY) } - fn handle_channel_announcement(&self, msg: &msgs::ChannelAnnouncement) -> Result { + fn handle_channel_announcement(&self, _their_node_id: Option, msg: &msgs::ChannelAnnouncement) -> Result { self.network_graph.update_channel_from_announcement(msg, &*self.utxo_lookup.read().unwrap())?; Ok(msg.contents.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY) } - fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result { + fn handle_channel_update(&self, _their_node_id: Option, msg: &msgs::ChannelUpdate) -> Result { self.network_graph.update_channel(msg)?; Ok(msg.contents.excess_data.len() <= MAX_EXCESS_BYTES_FOR_RELAY) } @@ -555,7 +555,7 @@ where U::Target: UtxoLookup, L::Target: Logger /// [`query_channel_range`]: msgs::QueryChannelRange /// [`query_scid`]: msgs::QueryShortChannelIds /// [`reply_scids_end`]: msgs::ReplyShortChannelIdsEnd - fn peer_connected(&self, their_node_id: &PublicKey, init_msg: &Init, _inbound: bool) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: PublicKey, init_msg: &Init, _inbound: bool) -> Result<(), ()> { // We will only perform a sync with peers that support gossip_queries. if !init_msg.features.supports_gossip_queries() { // Don't disconnect peers for not supporting gossip queries. We may wish to have @@ -612,7 +612,7 @@ where U::Target: UtxoLookup, L::Target: Logger // our peers and never receiving gossip from peers at all, we send all of our peers a // `gossip_timestamp_filter`, with the filter time set either two weeks ago or an hour ago. // - // For no-std builds, we bury our head in the sand and do a full sync on each connection. + // For non-`std` builds, we bury our head in the sand and do a full sync on each connection. #[allow(unused_mut, unused_assignments)] let mut gossip_start_time = 0; #[allow(unused)] @@ -639,14 +639,14 @@ where U::Target: UtxoLookup, L::Target: Logger Ok(()) } - fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: ReplyChannelRange) -> Result<(), LightningError> { + fn handle_reply_channel_range(&self, _their_node_id: PublicKey, _msg: ReplyChannelRange) -> Result<(), LightningError> { // We don't make queries, so should never receive replies. If, in the future, the set // reconciliation extensions to gossip queries become broadly supported, we should revert // this code to its state pre-0.0.106. Ok(()) } - fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { + fn handle_reply_short_channel_ids_end(&self, _their_node_id: PublicKey, _msg: ReplyShortChannelIdsEnd) -> Result<(), LightningError> { // We don't make queries, so should never receive replies. If, in the future, the set // reconciliation extensions to gossip queries become broadly supported, we should revert // this code to its state pre-0.0.106. @@ -660,7 +660,7 @@ where U::Target: UtxoLookup, L::Target: Logger /// sync of the public routing table with 128k channels will generated 16 messages and allocate ~1MB. /// Logic can be changed to reduce allocation if/when a full sync of the routing table impacts /// memory constrained systems. - fn handle_query_channel_range(&self, their_node_id: &PublicKey, msg: QueryChannelRange) -> Result<(), LightningError> { + fn handle_query_channel_range(&self, their_node_id: PublicKey, msg: QueryChannelRange) -> Result<(), LightningError> { log_debug!(self.logger, "Handling query_channel_range peer={}, first_blocknum={}, number_of_blocks={}", log_pubkey!(their_node_id), msg.first_blocknum, msg.number_of_blocks); let inclusive_start_scid = scid_from_parts(msg.first_blocknum as u64, 0, 0); @@ -757,7 +757,7 @@ where U::Target: UtxoLookup, L::Target: Logger Ok(()) } - fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: QueryShortChannelIds) -> Result<(), LightningError> { + fn handle_query_short_channel_ids(&self, _their_node_id: PublicKey, _msg: QueryShortChannelIds) -> Result<(), LightningError> { // TODO Err(LightningError { err: String::from("Not implemented"), @@ -771,7 +771,7 @@ where U::Target: UtxoLookup, L::Target: Logger features } - fn provided_init_features(&self, _their_node_id: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures { let mut features = InitFeatures::empty(); features.set_gossip_queries_optional(); features @@ -934,7 +934,7 @@ pub struct ChannelInfo { /// Not stored if contains excess data to prevent DoS. pub announcement_message: Option, /// The timestamp when we received the announcement, if we are running with feature = "std" - /// (which we can probably assume we are - no-std environments probably won't have a full + /// (which we can probably assume we are - non-`std` environments probably won't have a full /// network graph in memory!). announcement_received_time: u64, } @@ -1720,6 +1720,15 @@ impl NetworkGraph where L::Target: Logger { /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. pub fn update_node_from_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<(), LightningError> { + // First check if we have the announcement already to avoid the CPU cost of validating a + // redundant announcement. + if let Some(node) = self.nodes.read().unwrap().get(&msg.contents.node_id) { + if let Some(node_info) = node.announcement_info.as_ref() { + if node_info.last_update() == msg.contents.timestamp { + return Err(LightningError{err: "Update had the same timestamp as last processed update".to_owned(), action: ErrorAction::IgnoreDuplicateGossip}); + } + } + } verify_node_announcement(msg, &self.secp_ctx)?; self.update_node_from_announcement_intern(&msg.contents, Some(&msg)) } @@ -1788,6 +1797,7 @@ impl NetworkGraph where L::Target: Logger { where U::Target: UtxoLookup, { + self.pre_channel_announcement_validation_check(&msg.contents, utxo_lookup)?; verify_channel_announcement(msg, &self.secp_ctx)?; self.update_channel_from_unsigned_announcement_intern(&msg.contents, Some(msg), utxo_lookup) } @@ -1817,6 +1827,7 @@ impl NetworkGraph where L::Target: Logger { where U::Target: UtxoLookup, { + self.pre_channel_announcement_validation_check(&msg, utxo_lookup)?; self.update_channel_from_unsigned_announcement_intern(msg, None, utxo_lookup) } @@ -1911,6 +1922,52 @@ impl NetworkGraph where L::Target: Logger { Ok(()) } + /// If we already have all the information for a channel that we're gonna get, there's no + /// reason to redundantly process it. + /// + /// In those cases, this will return an `Err` that we can return immediately. Otherwise it will + /// return an `Ok(())`. + fn pre_channel_announcement_validation_check( + &self, msg: &msgs::UnsignedChannelAnnouncement, utxo_lookup: &Option, + ) -> Result<(), LightningError> where U::Target: UtxoLookup { + let channels = self.channels.read().unwrap(); + + if let Some(chan) = channels.get(&msg.short_channel_id) { + if chan.capacity_sats.is_some() { + // If we'd previously looked up the channel on-chain and checked the script + // against what appears on-chain, ignore the duplicate announcement. + // + // Because a reorg could replace one channel with another at the same SCID, if + // the channel appears to be different, we re-validate. This doesn't expose us + // to any more DoS risk than not, as a peer can always flood us with + // randomly-generated SCID values anyway. + // + // We use the Node IDs rather than the bitcoin_keys to check for "equivalence" + // as we didn't (necessarily) store the bitcoin keys, and we only really care + // if the peers on the channel changed anyway. + if msg.node_id_1 == chan.node_one && msg.node_id_2 == chan.node_two { + return Err(LightningError { + err: "Already have chain-validated channel".to_owned(), + action: ErrorAction::IgnoreDuplicateGossip + }); + } + } else if utxo_lookup.is_none() { + // Similarly, if we can't check the chain right now anyway, ignore the + // duplicate announcement without bothering to take the channels write lock. + return Err(LightningError { + err: "Already have non-chain-validated channel".to_owned(), + action: ErrorAction::IgnoreDuplicateGossip + }); + } + } + + Ok(()) + } + + /// Update channel information from a received announcement. + /// + /// Generally [`Self::pre_channel_announcement_validation_check`] should have been called + /// first. fn update_channel_from_unsigned_announcement_intern( &self, msg: &msgs::UnsignedChannelAnnouncement, full_msg: Option<&msgs::ChannelAnnouncement>, utxo_lookup: &Option ) -> Result<(), LightningError> @@ -1928,39 +1985,6 @@ impl NetworkGraph where L::Target: Logger { }); } - { - let channels = self.channels.read().unwrap(); - - if let Some(chan) = channels.get(&msg.short_channel_id) { - if chan.capacity_sats.is_some() { - // If we'd previously looked up the channel on-chain and checked the script - // against what appears on-chain, ignore the duplicate announcement. - // - // Because a reorg could replace one channel with another at the same SCID, if - // the channel appears to be different, we re-validate. This doesn't expose us - // to any more DoS risk than not, as a peer can always flood us with - // randomly-generated SCID values anyway. - // - // We use the Node IDs rather than the bitcoin_keys to check for "equivalence" - // as we didn't (necessarily) store the bitcoin keys, and we only really care - // if the peers on the channel changed anyway. - if msg.node_id_1 == chan.node_one && msg.node_id_2 == chan.node_two { - return Err(LightningError { - err: "Already have chain-validated channel".to_owned(), - action: ErrorAction::IgnoreDuplicateGossip - }); - } - } else if utxo_lookup.is_none() { - // Similarly, if we can't check the chain right now anyway, ignore the - // duplicate announcement without bothering to take the channels write lock. - return Err(LightningError { - err: "Already have non-chain-validated channel".to_owned(), - action: ErrorAction::IgnoreDuplicateGossip - }); - } - } - } - { let removed_channels = self.removed_channels.lock().unwrap(); let removed_nodes = self.removed_nodes.lock().unwrap(); @@ -2081,7 +2105,7 @@ impl NetworkGraph where L::Target: Logger { /// in the map for a while so that these can be resynced from gossip in the future. /// /// This method is only available with the `std` feature. See - /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use. + /// [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for non-`std` use. pub fn remove_stale_channels_and_tracking(&self) { let time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs(); self.remove_stale_channels_and_tracking_with_time(time); @@ -2097,9 +2121,9 @@ impl NetworkGraph where L::Target: Logger { /// /// This method will also cause us to stop tracking removed nodes and channels if they have been /// in the map for a while so that these can be resynced from gossip in the future. - /// - /// This function takes the current unix time as an argument. For users with the `std` feature - /// enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable. + #[cfg_attr(feature = "std", doc = "")] + #[cfg_attr(feature = "std", doc = "This function takes the current unix time as an argument. For users with the `std` feature")] + #[cfg_attr(feature = "std", doc = "enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.")] pub fn remove_stale_channels_and_tracking_with_time(&self, current_time_unix: u64) { let mut channels = self.channels.write().unwrap(); // Time out if we haven't received an update in at least 14 days. @@ -2145,7 +2169,7 @@ impl NetworkGraph where L::Target: Logger { if let Some(time) = time { current_time_unix.saturating_sub(*time) < REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS } else { - // NOTE: In the case of no-std, we won't have access to the current UNIX time at the time of removal, + // NOTE: In the case of non-`std`, we won't have access to the current UNIX time at the time of removal, // so we'll just set the removal time here to the current UNIX time on the very next invocation // of this function. #[cfg(not(feature = "std"))] @@ -2169,7 +2193,7 @@ impl NetworkGraph where L::Target: Logger { /// [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept /// routing messages from a source using a protocol other than the lightning P2P protocol. /// - /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or + /// If not built with `std`, any updates with a timestamp more than two weeks in the past or /// materially in the future will be rejected. pub fn update_channel(&self, msg: &msgs::ChannelUpdate) -> Result<(), LightningError> { self.update_channel_internal(&msg.contents, Some(&msg), Some(&msg.signature), false) @@ -2179,7 +2203,7 @@ impl NetworkGraph where L::Target: Logger { /// of the channel without verifying the associated signatures. Because we aren't given the /// associated signatures here we cannot relay the channel update to any of our peers. /// - /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or + /// If not built with `std`, any updates with a timestamp more than two weeks in the past or /// materially in the future will be rejected. pub fn update_channel_unsigned(&self, msg: &msgs::UnsignedChannelUpdate) -> Result<(), LightningError> { self.update_channel_internal(msg, None, None, false) @@ -2189,7 +2213,7 @@ impl NetworkGraph where L::Target: Logger { /// /// This checks whether the update currently is applicable by [`Self::update_channel`]. /// - /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or + /// If not built with `std`, any updates with a timestamp more than two weeks in the past or /// materially in the future will be rejected. pub fn verify_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<(), LightningError> { self.update_channel_internal(&msg.contents, Some(&msg), Some(&msg.signature), true) @@ -2544,11 +2568,12 @@ pub(crate) mod tests { let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let zero_hash = Sha256dHash::hash(&[0; 32]); let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!("No existing channels for node_announcement", e.err) }; @@ -2556,19 +2581,15 @@ pub(crate) mod tests { { // Announce a channel to add a corresponding node. let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; } - match gossip_sync.handle_node_announcement(&valid_announcement) { - Ok(res) => assert!(res), - Err(_) => panic!() - }; - let fake_msghash = hash_to_message!(zero_hash.as_byte_array()); match gossip_sync.handle_node_announcement( + Some(node_1_pubkey), &NodeAnnouncement { signature: secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey), contents: valid_announcement.contents.clone() @@ -2577,12 +2598,17 @@ pub(crate) mod tests { Err(e) => assert_eq!(e.err, "Invalid signature on node_announcement message") }; + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { + Ok(res) => assert!(res), + Err(_) => panic!() + }; + let announcement_with_data = get_signed_node_announcement(|unsigned_announcement| { unsigned_announcement.timestamp += 1000; unsigned_announcement.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, &secp_ctx); // Return false because contains excess data. - match gossip_sync.handle_node_announcement(&announcement_with_data) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement_with_data) { Ok(res) => assert!(!res), Err(_) => panic!() }; @@ -2592,7 +2618,7 @@ pub(crate) mod tests { let outdated_announcement = get_signed_node_announcement(|unsigned_announcement| { unsigned_announcement.timestamp += 1000 - 10; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&outdated_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &outdated_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Update older than last processed update") }; @@ -2604,6 +2630,7 @@ pub(crate) mod tests { let logger = test_utils::TestLogger::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let good_script = get_channel_script(&secp_ctx); @@ -2612,7 +2639,7 @@ pub(crate) mod tests { // Test if the UTXO lookups were not supported let network_graph = NetworkGraph::new(Network::Testnet, &logger); let mut gossip_sync = P2PGossipSync::new(&network_graph, None, &logger); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -2626,7 +2653,7 @@ pub(crate) mod tests { // If we receive announcement for the same channel (with UTXO lookups disabled), // drop new one on the floor, since we can't see any changes. - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Already have non-chain-validated channel") }; @@ -2640,7 +2667,7 @@ pub(crate) mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 1; }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announced without corresponding UTXO entry") }; @@ -2651,7 +2678,7 @@ pub(crate) mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 2; }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -2667,7 +2694,7 @@ pub(crate) mod tests { // chain, we simply ignore all new (duplicate) announcements. *chain_source.utxo_ret.lock().unwrap() = UtxoResult::Sync(Ok(TxOut { value: Amount::ZERO, script_pubkey: good_script })); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Already have chain-validated channel") }; @@ -2684,7 +2711,7 @@ pub(crate) mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 3; }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel with SCID 3 or one of its nodes was removed from our network graph recently") } @@ -2692,31 +2719,32 @@ pub(crate) mod tests { gossip_sync.network_graph().remove_stale_channels_and_tracking_with_time(tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS); // The above channel announcement should be handled as per normal now. - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() } } - // Don't relay valid channels with excess data - let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { + let valid_excess_data_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id += 4; unsigned_announcement.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { - Ok(res) => assert!(!res), - _ => panic!() - }; - let mut invalid_sig_announcement = valid_announcement.clone(); + let mut invalid_sig_announcement = valid_excess_data_announcement.clone(); invalid_sig_announcement.contents.excess_data = Vec::new(); - match gossip_sync.handle_channel_announcement(&invalid_sig_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &invalid_sig_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Invalid signature on channel_announcement message") }; + // Don't relay valid channels with excess data + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_excess_data_announcement) { + Ok(res) => assert!(!res), + _ => panic!() + }; + let channel_to_itself_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&channel_to_itself_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &channel_to_itself_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announcement node had a channel with itself") }; @@ -2726,7 +2754,7 @@ pub(crate) mod tests { let incorrect_chain_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.chain_hash = ChainHash::using_genesis_block(Network::Bitcoin); }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&incorrect_chain_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &incorrect_chain_announcement) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel announcement chain hash does not match genesis hash") }; @@ -2741,6 +2769,7 @@ pub(crate) mod tests { let gossip_sync = P2PGossipSync::new(&network_graph, Some(&chain_source), &logger); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let amount_sats = Amount::from_sat(1000_000); @@ -2754,7 +2783,7 @@ pub(crate) mod tests { let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); short_channel_id = valid_channel_announcement.contents.short_channel_id; - match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -2763,7 +2792,7 @@ pub(crate) mod tests { let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx); network_graph.verify_channel_update(&valid_channel_update).unwrap(); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(res) => assert!(res), _ => panic!(), }; @@ -2783,7 +2812,7 @@ pub(crate) mod tests { unsigned_channel_update.excess_data.resize(MAX_EXCESS_BYTES_FOR_RELAY + 1, 0); }, node_1_privkey, &secp_ctx); // Return false because contains excess data - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(res) => assert!(!res), _ => panic!() }; @@ -2792,7 +2821,7 @@ pub(crate) mod tests { unsigned_channel_update.timestamp += 110; unsigned_channel_update.short_channel_id += 1; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Couldn't find channel for update") }; @@ -2801,7 +2830,7 @@ pub(crate) mod tests { unsigned_channel_update.htlc_maximum_msat = MAX_VALUE_MSAT + 1; unsigned_channel_update.timestamp += 110; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "htlc_maximum_msat is larger than maximum possible msats") }; @@ -2810,7 +2839,7 @@ pub(crate) mod tests { unsigned_channel_update.htlc_maximum_msat = amount_sats.to_sat() * 1000 + 1; unsigned_channel_update.timestamp += 110; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "htlc_maximum_msat is larger than channel capacity or capacity is bogus") }; @@ -2820,7 +2849,7 @@ pub(crate) mod tests { let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| { unsigned_channel_update.timestamp += 100; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Update had same timestamp as last processed update") }; @@ -2831,7 +2860,7 @@ pub(crate) mod tests { let zero_hash = Sha256dHash::hash(&[0; 32]); let fake_msghash = hash_to_message!(zero_hash.as_byte_array()); invalid_sig_channel_update.signature = secp_ctx.sign_ecdsa(&fake_msghash, node_1_privkey); - match gossip_sync.handle_channel_update(&invalid_sig_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &invalid_sig_channel_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Invalid signature on channel_update message") }; @@ -2842,7 +2871,7 @@ pub(crate) mod tests { unsigned_channel_update.chain_hash = ChainHash::using_genesis_block(Network::Bitcoin); }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&incorrect_chain_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &incorrect_chain_update) { Ok(_) => panic!(), Err(e) => assert_eq!(e.err, "Channel update chain hash does not match genesis hash") }; @@ -2953,6 +2982,7 @@ pub(crate) mod tests { let secp_ctx = Secp256k1::new(); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); @@ -2963,11 +2993,11 @@ pub(crate) mod tests { // Submit two channel updates for each channel direction (update.flags bit). let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx); - assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok()); + assert!(gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update).is_ok()); assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some()); let valid_channel_update_2 = get_signed_channel_update(|update| {update.channel_flags |=1;}, node_2_privkey, &secp_ctx); - gossip_sync.handle_channel_update(&valid_channel_update_2).unwrap(); + gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update_2).unwrap(); assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().two_to_one.is_some()); network_graph.remove_stale_channels_and_tracking_with_time(100 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS); @@ -2999,7 +3029,7 @@ pub(crate) mod tests { let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| { unsigned_channel_update.timestamp = (announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS) as u32; }, node_1_privkey, &secp_ctx); - assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok()); + assert!(gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update).is_ok()); assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some()); network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS); // Make sure removed channels are tracked. @@ -3082,6 +3112,7 @@ pub(crate) mod tests { let network_graph = create_network_graph(); let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); // Channels were not announced yet. @@ -3093,7 +3124,7 @@ pub(crate) mod tests { // Announce a channel we will update let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); short_channel_id = valid_channel_announcement.contents.short_channel_id; - match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -3114,7 +3145,7 @@ pub(crate) mod tests { let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| { unsigned_channel_update.timestamp = 101; }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => (), Err(_) => panic!() }; @@ -3136,7 +3167,7 @@ pub(crate) mod tests { unsigned_channel_update.timestamp = 102; unsigned_channel_update.excess_data = [1; MAX_EXCESS_BYTES_FOR_RELAY + 1].to_vec(); }, node_1_privkey, &secp_ctx); - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_1_pubkey), &valid_channel_update) { Ok(_) => (), Err(_) => panic!() }; @@ -3162,6 +3193,7 @@ pub(crate) mod tests { let network_graph = create_network_graph(); let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id_1 = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_1_privkey)); @@ -3172,7 +3204,7 @@ pub(crate) mod tests { { // Announce a channel to add 2 nodes let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_channel_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_channel_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -3184,13 +3216,13 @@ pub(crate) mod tests { { let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => (), Err(_) => panic!() }; let valid_announcement = get_signed_node_announcement(|_| {}, node_2_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -3209,7 +3241,7 @@ pub(crate) mod tests { unsigned_announcement.timestamp += 10; unsigned_announcement.excess_data = [1; MAX_EXCESS_BYTES_FOR_RELAY + 1].to_vec(); }, node_2_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(!res), Err(_) => panic!() }; @@ -3225,17 +3257,18 @@ pub(crate) mod tests { let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); // Announce a channel to add a corresponding node. let valid_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; let valid_announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -3279,7 +3312,7 @@ pub(crate) mod tests { // It should ignore if gossip_queries feature is not enabled { let init_msg = Init { features: InitFeatures::empty(), networks: None, remote_network_address: None }; - gossip_sync.peer_connected(&node_id_1, &init_msg, true).unwrap(); + gossip_sync.peer_connected(node_id_1, &init_msg, true).unwrap(); let events = gossip_sync.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 0); } @@ -3289,7 +3322,7 @@ pub(crate) mod tests { let mut features = InitFeatures::empty(); features.set_gossip_queries_optional(); let init_msg = Init { features, networks: None, remote_network_address: None }; - gossip_sync.peer_connected(&node_id_1, &init_msg, true).unwrap(); + gossip_sync.peer_connected(node_id_1, &init_msg, true).unwrap(); let events = gossip_sync.get_and_clear_pending_msg_events(); assert_eq!(events.len(), 1); match &events[0] { @@ -3313,6 +3346,7 @@ pub(crate) mod tests { let chain_hash = ChainHash::using_genesis_block(Network::Testnet); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_id_2 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey); @@ -3333,7 +3367,7 @@ pub(crate) mod tests { let valid_announcement = get_signed_channel_announcement(|unsigned_announcement| { unsigned_announcement.short_channel_id = scid; }, node_1_privkey, node_2_privkey, &secp_ctx); - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(_) => (), _ => panic!() }; @@ -3559,7 +3593,7 @@ pub(crate) mod tests { let mut max_firstblocknum = msg.first_blocknum.saturating_sub(1); let mut c_lightning_0_9_prev_end_blocknum = max_firstblocknum; let query_end_blocknum = msg.end_blocknum(); - let result = gossip_sync.handle_query_channel_range(test_node_id, msg); + let result = gossip_sync.handle_query_channel_range(*test_node_id, msg); if expected_ok { assert!(result.is_ok()); @@ -3606,7 +3640,7 @@ pub(crate) mod tests { let chain_hash = ChainHash::using_genesis_block(Network::Testnet); - let result = gossip_sync.handle_query_short_channel_ids(&node_id, QueryShortChannelIds { + let result = gossip_sync.handle_query_short_channel_ids(node_id, QueryShortChannelIds { chain_hash, short_channel_ids: vec![0x0003e8_000000_0000], }); @@ -3791,11 +3825,12 @@ pub(crate) mod tests { let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph); let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap(); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap(); let node_1_id = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_1_privkey)); let announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx); - gossip_sync.handle_channel_announcement(&announcement).unwrap(); + gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &announcement).unwrap(); let tcp_ip_v4 = SocketAddress::TcpIpV4 { addr: [255, 254, 253, 252], @@ -3820,7 +3855,7 @@ pub(crate) mod tests { assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement(|_| {}, node_1_privkey, &secp_ctx); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3833,7 +3868,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3845,7 +3880,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3857,7 +3892,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3867,7 +3902,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3877,7 +3912,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); let announcement = get_signed_node_announcement( @@ -3887,7 +3922,7 @@ pub(crate) mod tests { }, node_1_privkey, &secp_ctx ); - gossip_sync.handle_node_announcement(&announcement).unwrap(); + gossip_sync.handle_node_announcement(Some(node_1_pubkey), &announcement).unwrap(); assert!(!network_graph.read_only().node(&node_1_id).unwrap().is_tor_only()); } } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index a25609c89bb..86295636b21 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -20,8 +20,10 @@ use crate::ln::channelmanager::{PaymentId, MIN_FINAL_CLTV_EXPIRY_DELTA, Recipien use crate::ln::features::{BlindedHopFeatures, Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures}; use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT}; use crate::ln::onion_utils; +#[cfg(async_payments)] +use crate::offers::static_invoice::StaticInvoice; use crate::offers::invoice::Bolt12Invoice; -use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; +use crate::onion_message::messenger::{BlindedPathType, DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId}; use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp}; use crate::sign::EntropySource; @@ -197,17 +199,10 @@ impl< G: Deref>, L: Deref, ES: Deref, S: Deref, SP: Siz fn create_blinded_paths< T: secp256k1::Signing + secp256k1::Verification > ( - &self, recipient: PublicKey, context: MessageContext, peers: Vec, secp_ctx: &Secp256k1, + &self, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, peers: Vec, + secp_ctx: &Secp256k1, ) -> Result, ()> { - DefaultMessageRouter::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx) - } - - fn create_compact_blinded_paths< - T: secp256k1::Signing + secp256k1::Verification - > ( - &self, recipient: PublicKey, context: MessageContext, peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()> { - DefaultMessageRouter::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx) + DefaultMessageRouter::create_blinded_paths(&self.network_graph, recipient, context, blinded_path, peers, &self.entropy_source, secp_ctx) } } @@ -877,6 +872,16 @@ impl PaymentParameters { .with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs())) } + /// Creates parameters for paying to a blinded payee from the provided invoice. Sets + /// [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and + /// [`PaymentParameters::expiry_time`]. + #[cfg(async_payments)] + pub fn from_static_invoice(invoice: &StaticInvoice) -> Self { + Self::blinded(invoice.payment_paths().to_vec()) + .with_bolt12_features(invoice.invoice_features().clone()).unwrap() + .with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs())) + } + /// Creates parameters for paying to a blinded payee from the provided blinded route hints. pub fn blinded(blinded_route_hints: Vec) -> Self { Self { @@ -3609,7 +3614,6 @@ mod tests { inbound_scid_alias: None, channel_value_satoshis: 0, user_channel_id: 0, - balance_msat: 0, outbound_capacity_msat, next_outbound_htlc_limit_msat: outbound_capacity_msat, next_outbound_htlc_minimum_msat: 0, @@ -8793,7 +8797,6 @@ pub(crate) mod bench_utils { outbound_scid_alias: None, channel_value_satoshis: 10_000_000_000, user_channel_id: 0, - balance_msat: 10_000_000_000, outbound_capacity_msat: 10_000_000_000, next_outbound_htlc_minimum_msat: 0, next_outbound_htlc_limit_msat: 10_000_000_000, diff --git a/lightning/src/routing/scoring.rs b/lightning/src/routing/scoring.rs index d40b1f22c40..b27a9f97b02 100644 --- a/lightning/src/routing/scoring.rs +++ b/lightning/src/routing/scoring.rs @@ -749,7 +749,7 @@ pub struct ProbabilisticScoringDecayParameters { /// /// # Note /// - /// When built with the `no-std` feature, time will never elapse. Therefore, the channel + /// When not built with the `std` feature, time will never elapse. Therefore, the channel /// liquidity knowledge will never decay except when the bounds cross. pub liquidity_offset_half_life: Duration, } diff --git a/lightning/src/routing/test_utils.rs b/lightning/src/routing/test_utils.rs index cf991ed0a40..a64955cd015 100644 --- a/lightning/src/routing/test_utils.rs +++ b/lightning/src/routing/test_utils.rs @@ -32,7 +32,8 @@ pub(crate) fn add_channel( gossip_sync: &P2PGossipSync>>, Arc, Arc>, secp_ctx: &Secp256k1, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64 ) { - let node_id_1 = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_1_privkey)); + let node_1_pubkey = PublicKey::from_secret_key(&secp_ctx, node_1_privkey); + let node_id_1 = NodeId::from_pubkey(&node_1_pubkey); let node_id_2 = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_2_privkey)); let unsigned_announcement = UnsignedChannelAnnouncement { @@ -54,7 +55,7 @@ pub(crate) fn add_channel( bitcoin_signature_2: secp_ctx.sign_ecdsa(&msghash, node_2_privkey), contents: unsigned_announcement.clone(), }; - match gossip_sync.handle_channel_announcement(&valid_announcement) { + match gossip_sync.handle_channel_announcement(Some(node_1_pubkey), &valid_announcement) { Ok(res) => assert!(res), _ => panic!() }; @@ -64,7 +65,8 @@ pub(crate) fn add_or_update_node( gossip_sync: &P2PGossipSync>>, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32 ) { - let node_id = NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, node_privkey)); + let node_pubkey = PublicKey::from_secret_key(&secp_ctx, node_privkey); + let node_id = NodeId::from_pubkey(&node_pubkey); let unsigned_announcement = UnsignedNodeAnnouncement { features, timestamp, @@ -81,7 +83,7 @@ pub(crate) fn add_or_update_node( contents: unsigned_announcement.clone() }; - match gossip_sync.handle_node_announcement(&valid_announcement) { + match gossip_sync.handle_node_announcement(Some(node_pubkey), &valid_announcement) { Ok(_) => (), Err(_) => panic!() }; @@ -91,13 +93,14 @@ pub(crate) fn update_channel( gossip_sync: &P2PGossipSync>>, Arc, Arc>, secp_ctx: &Secp256k1, node_privkey: &SecretKey, update: UnsignedChannelUpdate ) { + let node_pubkey = PublicKey::from_secret_key(&secp_ctx, node_privkey); let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]); let valid_channel_update = ChannelUpdate { signature: secp_ctx.sign_ecdsa(&msghash, node_privkey), contents: update.clone() }; - match gossip_sync.handle_channel_update(&valid_channel_update) { + match gossip_sync.handle_channel_update(Some(node_pubkey), &valid_channel_update) { Ok(res) => assert!(res), Err(_) => panic!() }; diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 0d3ec9efa41..8ad34f2d653 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -878,7 +878,7 @@ pub trait NodeSigner { /// Implementors may check that the `invoice_request` is expected rather than blindly signing /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with - /// [`UnsignedInvoiceRequest::payer_id`]. + /// [`UnsignedInvoiceRequest::payer_signing_pubkey`]. /// /// [`TaggedHash`]: crate::offers::merkle::TaggedHash fn sign_bolt12_invoice_request( @@ -1027,7 +1027,6 @@ pub trait ChangeDestinationSource { /// /// This implementation performs no policy checks and is insufficient by itself as /// a secure external signer. -#[derive(Debug)] pub struct InMemorySigner { /// Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the /// holder's anchor output in a commitment transaction, if one is present. @@ -1854,6 +1853,9 @@ pub struct KeysManager { channel_master_key: Xpriv, channel_child_index: AtomicUsize, + #[cfg(test)] + pub(crate) entropy_source: RandomBytes, + #[cfg(not(test))] entropy_source: RandomBytes, seed: [u8; 32], @@ -2310,6 +2312,9 @@ impl SignerProvider for KeysManager { /// Switching between this struct and [`KeysManager`] will invalidate any previously issued /// invoices and attempts to pay previous invoices will fail. pub struct PhantomKeysManager { + #[cfg(test)] + pub(crate) inner: KeysManager, + #[cfg(not(test))] inner: KeysManager, inbound_payment_key: KeyMaterial, phantom_secret: SecretKey, @@ -2475,7 +2480,6 @@ impl PhantomKeysManager { } /// An implementation of [`EntropySource`] using ChaCha20. -#[derive(Debug)] pub struct RandomBytes { /// Seed from which all randomness produced is derived from. seed: [u8; 32], @@ -2489,11 +2493,18 @@ impl RandomBytes { pub fn new(seed: [u8; 32]) -> Self { Self { seed, index: AtomicCounter::new() } } + + #[cfg(test)] + /// Force the counter to a value to produce the same output again. Mostly useful in tests where + /// we need to maintain behavior with a previous version which didn't use as much RNG output. + pub(crate) fn set_counter(&self, count: u64) { + self.index.set_counter(count); + } } impl EntropySource for RandomBytes { fn get_secure_random_bytes(&self) -> [u8; 32] { - let index = self.index.get_increment(); + let index = self.index.next(); let mut nonce = [0u8; 16]; nonce[..8].copy_from_slice(&index.to_be_bytes()); ChaCha20::get_single_block(&self.seed, &nonce) diff --git a/lightning/src/sync/debug_sync.rs b/lightning/src/sync/debug_sync.rs index 5968a79ee4d..776e35e8ce0 100644 --- a/lightning/src/sync/debug_sync.rs +++ b/lightning/src/sync/debug_sync.rs @@ -1,30 +1,34 @@ -pub use ::alloc::sync::Arc; +pub use alloc::sync::Arc; use core::ops::{Deref, DerefMut}; use core::time::Duration; use std::cell::RefCell; use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::Condvar as StdCondvar; use std::sync::Mutex as StdMutex; use std::sync::MutexGuard as StdMutexGuard; use std::sync::RwLock as StdRwLock; use std::sync::RwLockReadGuard as StdRwLockReadGuard; use std::sync::RwLockWriteGuard as StdRwLockWriteGuard; -use std::sync::Condvar as StdCondvar; pub use std::sync::WaitTimeoutResult; use crate::prelude::*; -use super::{LockTestExt, LockHeldState}; +use super::{LockHeldState, LockTestExt}; #[cfg(feature = "backtrace")] use {crate::prelude::hash_map, backtrace::Backtrace, std::sync::Once}; #[cfg(not(feature = "backtrace"))] -struct Backtrace{} +struct Backtrace {} #[cfg(not(feature = "backtrace"))] -impl Backtrace { fn new() -> Backtrace { Backtrace {} } } +impl Backtrace { + fn new() -> Backtrace { + Backtrace {} + } +} pub type LockResult = Result; @@ -37,22 +41,30 @@ impl Condvar { Condvar { inner: StdCondvar::new() } } - pub fn wait_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, condition: F) - -> LockResult> { + pub fn wait_while<'a, T, F: FnMut(&mut T) -> bool>( + &'a self, guard: MutexGuard<'a, T>, condition: F, + ) -> LockResult> { let mutex: &'a Mutex = guard.mutex; - self.inner.wait_while(guard.into_inner(), condition).map(|lock| MutexGuard { mutex, lock }) + self.inner + .wait_while(guard.into_inner(), condition) + .map(|lock| MutexGuard { mutex, lock }) .map_err(|_| ()) } #[allow(unused)] - pub fn wait_timeout_while<'a, T, F: FnMut(&mut T) -> bool>(&'a self, guard: MutexGuard<'a, T>, dur: Duration, condition: F) - -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> { + pub fn wait_timeout_while<'a, T, F: FnMut(&mut T) -> bool>( + &'a self, guard: MutexGuard<'a, T>, dur: Duration, condition: F, + ) -> LockResult<(MutexGuard<'a, T>, WaitTimeoutResult)> { let mutex = guard.mutex; - self.inner.wait_timeout_while(guard.into_inner(), dur, condition).map_err(|_| ()) + self.inner + .wait_timeout_while(guard.into_inner(), dur, condition) + .map_err(|_| ()) .map(|(lock, e)| (MutexGuard { mutex, lock }, e)) } - pub fn notify_all(&self) { self.inner.notify_all(); } + pub fn notify_all(&self) { + self.inner.notify_all(); + } } thread_local! { @@ -99,14 +111,19 @@ fn locate_call_symbol(backtrace: &Backtrace) -> (String, Option) { symbol_after_latest_debug_sync = Some(symbol); found_debug_sync = false; } - } else { found_debug_sync = true; } + } else { + found_debug_sync = true; + } } } } let symbol = symbol_after_latest_debug_sync.unwrap_or_else(|| { panic!("Couldn't find lock call symbol in trace {:?}", backtrace); }); - (format!("{}:{}", symbol.filename().unwrap().display(), symbol.lineno().unwrap()), symbol.colno()) + ( + format!("{}:{}", symbol.filename().unwrap().display(), symbol.lineno().unwrap()), + symbol.colno(), + ) } impl LockMetadata { @@ -124,16 +141,20 @@ impl LockMetadata { { let (lock_constr_location, lock_constr_colno) = locate_call_symbol(&res._lock_construction_bt); - LOCKS_INIT.call_once(|| { unsafe { LOCKS = Some(StdMutex::new(new_hash_map())); } }); + LOCKS_INIT.call_once(|| unsafe { + LOCKS = Some(StdMutex::new(new_hash_map())); + }); let mut locks = unsafe { LOCKS.as_ref() }.unwrap().lock().unwrap(); match locks.entry(lock_constr_location) { hash_map::Entry::Occupied(e) => { assert_eq!(lock_constr_colno, locate_call_symbol(&e.get()._lock_construction_bt).1, "Because Windows doesn't support column number results in backtraces, we cannot construct two mutexes on the same line or we risk lockorder detection false positives."); - return Arc::clone(e.get()) + return Arc::clone(e.get()); + }, + hash_map::Entry::Vacant(e) => { + e.insert(Arc::clone(&res)); }, - hash_map::Entry::Vacant(e) => { e.insert(Arc::clone(&res)); }, } } res @@ -213,7 +234,8 @@ impl LockMetadata { let mut locked_before = this.locked_before.lock().unwrap(); for (locked_idx, locked) in held.borrow().iter() { if !locked_before.contains_key(locked_idx) { - let lockdep = LockDep { lock: Arc::clone(locked), _lockdep_trace: Backtrace::new() }; + let lockdep = + LockDep { lock: Arc::clone(locked), _lockdep_trace: Backtrace::new() }; locked_before.insert(*locked_idx, lockdep); } } @@ -282,7 +304,8 @@ impl Mutex { } pub fn try_lock<'a>(&'a self) -> LockResult> { - let res = self.inner.try_lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ()); + let res = + self.inner.try_lock().map(|lock| MutexGuard { mutex: self, lock }).map_err(|_| ()); if res.is_ok() { LockMetadata::try_locked(&self.deps); } @@ -376,7 +399,11 @@ impl RwLock { } pub fn try_write<'a>(&'a self) -> LockResult> { - let res = self.inner.try_write().map(|guard| RwLockWriteGuard { lock: self, guard }).map_err(|_| ()); + let res = self + .inner + .try_write() + .map(|guard| RwLockWriteGuard { lock: self, guard }) + .map_err(|_| ()); if res.is_ok() { LockMetadata::try_locked(&self.deps); } diff --git a/lightning/src/sync/fairrwlock.rs b/lightning/src/sync/fairrwlock.rs index 23b8c23db28..d97370090cd 100644 --- a/lightning/src/sync/fairrwlock.rs +++ b/lightning/src/sync/fairrwlock.rs @@ -1,6 +1,6 @@ -use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockResult}; -use std::sync::atomic::{AtomicUsize, Ordering}; use super::{LockHeldState, LockTestExt}; +use std::sync::atomic::{AtomicUsize, Ordering}; +use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockResult}; /// Rust libstd's RwLock does not provide any fairness guarantees (and, in fact, when used on /// Linux with pthreads under the hood, readers trivially and completely starve writers). diff --git a/lightning/src/sync/mod.rs b/lightning/src/sync/mod.rs index 348bd90274a..0d0a76e3f2e 100644 --- a/lightning/src/sync/mod.rs +++ b/lightning/src/sync/mod.rs @@ -31,24 +31,35 @@ mod test_lockorder_checks; #[cfg(all(feature = "std", any(ldk_bench, not(test))))] pub(crate) mod fairrwlock; #[cfg(all(feature = "std", any(ldk_bench, not(test))))] -pub use {std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, fairrwlock::FairRwLock}; +pub use { + fairrwlock::FairRwLock, + std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, +}; #[cfg(all(feature = "std", any(ldk_bench, not(test))))] mod ext_impl { use super::*; impl<'a, T: 'a> LockTestExt<'a> for Mutex { #[inline] - fn held_by_thread(&self) -> LockHeldState { LockHeldState::Unsupported } + fn held_by_thread(&self) -> LockHeldState { + LockHeldState::Unsupported + } type ExclLock = MutexGuard<'a, T>; #[inline] - fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard { self.lock().unwrap() } + fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard { + self.lock().unwrap() + } } impl<'a, T: 'a> LockTestExt<'a> for RwLock { #[inline] - fn held_by_thread(&self) -> LockHeldState { LockHeldState::Unsupported } + fn held_by_thread(&self) -> LockHeldState { + LockHeldState::Unsupported + } type ExclLock = RwLockWriteGuard<'a, T>; #[inline] - fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard { self.write().unwrap() } + fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard { + self.write().unwrap() + } } } diff --git a/lightning/src/sync/nostd_sync.rs b/lightning/src/sync/nostd_sync.rs index 0f92bd6caa3..03fa65b69c6 100644 --- a/lightning/src/sync/nostd_sync.rs +++ b/lightning/src/sync/nostd_sync.rs @@ -1,12 +1,12 @@ -pub use ::alloc::sync::Arc; +use super::{LockHeldState, LockTestExt}; +pub use alloc::sync::Arc; +use core::cell::{Ref, RefCell, RefMut}; use core::ops::{Deref, DerefMut}; -use core::cell::{RefCell, Ref, RefMut}; -use super::{LockTestExt, LockHeldState}; pub type LockResult = Result; pub struct Mutex { - inner: RefCell + inner: RefCell, } #[must_use = "if unused the Mutex will immediately unlock"] @@ -45,16 +45,21 @@ impl Mutex { impl<'a, T: 'a> LockTestExt<'a> for Mutex { #[inline] fn held_by_thread(&self) -> LockHeldState { - if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } - else { return LockHeldState::NotHeldByThread; } + if self.inner.try_borrow_mut().is_err() { + return LockHeldState::HeldByThread; + } else { + return LockHeldState::NotHeldByThread; + } } type ExclLock = MutexGuard<'a, T>; #[inline] - fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard { self.lock().unwrap() } + fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard { + self.lock().unwrap() + } } pub struct RwLock { - inner: RefCell + inner: RefCell, } pub struct RwLockReadGuard<'a, T: ?Sized + 'a> { @@ -103,7 +108,7 @@ impl RwLock { pub fn try_write<'a>(&'a self) -> LockResult> { match self.inner.try_borrow_mut() { Ok(lock) => Ok(RwLockWriteGuard { lock }), - Err(_) => Err(()) + Err(_) => Err(()), } } } @@ -111,12 +116,17 @@ impl RwLock { impl<'a, T: 'a> LockTestExt<'a> for RwLock { #[inline] fn held_by_thread(&self) -> LockHeldState { - if self.inner.try_borrow_mut().is_err() { return LockHeldState::HeldByThread; } - else { return LockHeldState::NotHeldByThread; } + if self.inner.try_borrow_mut().is_err() { + return LockHeldState::HeldByThread; + } else { + return LockHeldState::NotHeldByThread; + } } type ExclLock = RwLockWriteGuard<'a, T>; #[inline] - fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard { self.write().unwrap() } + fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard { + self.write().unwrap() + } } pub type FairRwLock = RwLock; diff --git a/lightning/src/sync/test_lockorder_checks.rs b/lightning/src/sync/test_lockorder_checks.rs index 96e497d4439..91826342f8a 100644 --- a/lightning/src/sync/test_lockorder_checks.rs +++ b/lightning/src/sync/test_lockorder_checks.rs @@ -1,4 +1,4 @@ -use crate::sync::debug_sync::{RwLock, Mutex}; +use crate::sync::debug_sync::{Mutex, RwLock}; use super::{LockHeldState, LockTestExt}; diff --git a/lightning/src/util/atomic_counter.rs b/lightning/src/util/atomic_counter.rs index d2e01411313..050bcadf807 100644 --- a/lightning/src/util/atomic_counter.rs +++ b/lightning/src/util/atomic_counter.rs @@ -1,32 +1,44 @@ -//! A simple atomic counter that uses AtomicUsize to give a u64 counter. +//! A simple atomic counter that uses mutexes if the platform doesn't support atomic u64s. -#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64")))] -compile_error!("We need at least 32-bit pointers for atomic counter (and to have enough memory to run LDK)"); +#[cfg(target_has_atomic = "64")] +use core::sync::atomic::{AtomicU64, Ordering}; +#[cfg(not(target_has_atomic = "64"))] +use crate::sync::Mutex; -use core::sync::atomic::{AtomicUsize, Ordering}; - -#[derive(Debug)] pub(crate) struct AtomicCounter { - // Usize needs to be at least 32 bits to avoid overflowing both low and high. If usize is 64 - // bits we will never realistically count into high: - counter_low: AtomicUsize, - counter_high: AtomicUsize, + #[cfg(target_has_atomic = "64")] + counter: AtomicU64, + #[cfg(not(target_has_atomic = "64"))] + counter: Mutex, } impl AtomicCounter { pub(crate) fn new() -> Self { Self { - counter_low: AtomicUsize::new(0), - counter_high: AtomicUsize::new(0), + #[cfg(target_has_atomic = "64")] + counter: AtomicU64::new(0), + #[cfg(not(target_has_atomic = "64"))] + counter: Mutex::new(0), + } + } + pub(crate) fn next(&self) -> u64 { + #[cfg(target_has_atomic = "64")] { + self.counter.fetch_add(1, Ordering::AcqRel) + } + #[cfg(not(target_has_atomic = "64"))] { + let mut mtx = self.counter.lock().unwrap(); + *mtx += 1; + *mtx - 1 } } - pub(crate) fn get_increment(&self) -> u64 { - let low = self.counter_low.fetch_add(1, Ordering::AcqRel) as u64; - let high = if low == 0 { - self.counter_high.fetch_add(1, Ordering::AcqRel) as u64 - } else { - self.counter_high.load(Ordering::Acquire) as u64 - }; - (high << 32) | low + #[cfg(test)] + pub(crate) fn set_counter(&self, count: u64) { + #[cfg(target_has_atomic = "64")] { + self.counter.store(count, Ordering::Release); + } + #[cfg(not(target_has_atomic = "64"))] { + let mut mtx = self.counter.lock().unwrap(); + *mtx = count; + } } } diff --git a/lightning/src/util/hash_tables.rs b/lightning/src/util/hash_tables.rs index 6c3d1ec42cb..3debb42c8f0 100644 --- a/lightning/src/util/hash_tables.rs +++ b/lightning/src/util/hash_tables.rs @@ -1,67 +1,10 @@ -//! Generally LDK uses `std`'s `HashMap`s, however when building for no-std, LDK uses `hashbrown`'s -//! `HashMap`s with the `std` `SipHasher` and uses `getrandom` to opportunistically randomize it, -//! if randomization is available. +//! Generally LDK uses `hashbrown`'s `HashMap`s with the `std` `SipHasher` and uses `getrandom` to +//! opportunistically randomize it, if randomization is available. //! //! This module simply re-exports the `HashMap` used in LDK for public consumption. -#[cfg(feature = "hashbrown")] -extern crate hashbrown; -#[cfg(feature = "possiblyrandom")] -extern crate possiblyrandom; +pub(crate) use hashbrown::hash_map; -// For no-std builds, we need to use hashbrown, however, by default, it doesn't randomize the -// hashing and is vulnerable to HashDoS attacks. Thus, we use the core SipHasher when not using -// std, but use `getrandom` to randomize it if its available. - -#[cfg(not(feature = "hashbrown"))] -mod std_hashtables { - pub use std::collections::hash_map::RandomState; - pub use std::collections::HashMap; - - pub(crate) use std::collections::{hash_map, HashSet}; - - pub(crate) type OccupiedHashMapEntry<'a, K, V> = - std::collections::hash_map::OccupiedEntry<'a, K, V>; - pub(crate) type VacantHashMapEntry<'a, K, V> = - std::collections::hash_map::VacantEntry<'a, K, V>; - - /// Builds a new [`HashMap`]. - pub fn new_hash_map() -> HashMap { - HashMap::new() - } - /// Builds a new [`HashMap`] with the given capacity. - pub fn hash_map_with_capacity(cap: usize) -> HashMap { - HashMap::with_capacity(cap) - } - pub(crate) fn hash_map_from_iter< - K: core::hash::Hash + Eq, - V, - I: IntoIterator, - >( - iter: I, - ) -> HashMap { - HashMap::from_iter(iter) - } - - pub(crate) fn new_hash_set() -> HashSet { - HashSet::new() - } - pub(crate) fn hash_set_with_capacity(cap: usize) -> HashSet { - HashSet::with_capacity(cap) - } - pub(crate) fn hash_set_from_iter>( - iter: I, - ) -> HashSet { - HashSet::from_iter(iter) - } -} -#[cfg(not(feature = "hashbrown"))] -pub use std_hashtables::*; - -#[cfg(feature = "hashbrown")] -pub(crate) use self::hashbrown::hash_map; - -#[cfg(feature = "hashbrown")] mod hashbrown_tables { #[cfg(feature = "std")] mod hasher { @@ -85,7 +28,7 @@ mod hashbrown_tables { /// target platform. pub fn new() -> RandomState { let (k0, k1); - #[cfg(all(not(fuzzing), feature = "possiblyrandom"))] + #[cfg(not(fuzzing))] { let mut keys = [0; 16]; possiblyrandom::getpossiblyrandom(&mut keys); @@ -97,7 +40,7 @@ mod hashbrown_tables { k0 = u64::from_le_bytes(k0_bytes); k1 = u64::from_le_bytes(k1_bytes); } - #[cfg(any(fuzzing, not(feature = "possiblyrandom")))] + #[cfg(fuzzing)] { k0 = 0; k1 = 0; @@ -120,7 +63,6 @@ mod hashbrown_tables { } } - use super::*; pub use hasher::*; /// The HashMap type used in LDK. @@ -170,5 +112,5 @@ mod hashbrown_tables { res } } -#[cfg(feature = "hashbrown")] + pub use hashbrown_tables::*; diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 1c48463b89f..99d20b927b6 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -50,8 +50,8 @@ use crate::util::string::UntrustedString; /// serialization buffer size pub const MAX_BUF_SIZE: usize = 64 * 1024; -/// A simplified version of [`std::io::Write`] that exists largely for backwards compatibility. -/// An impl is provided for any type that also impls [`std::io::Write`]. +/// A simplified version of `std::io::Write` that exists largely for backwards compatibility. +/// An impl is provided for any type that also impls `std::io::Write`. /// /// This is not exported to bindings users as we only export serialization to/from byte arrays instead pub trait Writer { @@ -173,7 +173,7 @@ impl Writer for LengthCalculatingWriter { } } -/// Essentially [`std::io::Take`] but a bit simpler and with a method to walk the underlying stream +/// Essentially `std::io::Take` but a bit simpler and with a method to walk the underlying stream /// forward to ensure we always consume exactly the fixed length specified. /// /// This is not exported to bindings users as manual TLV building is not currently supported in bindings diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index e56b2d9c68d..178fb947aa1 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -872,6 +872,7 @@ macro_rules! _init_and_read_tlv_stream { /// /// [`Readable`]: crate::util::ser::Readable /// [`Writeable`]: crate::util::ser::Writeable +/// [`Vec`]: crate::prelude::Vec #[macro_export] macro_rules! impl_writeable_tlv_based { ($st: ident, {$(($type: expr, $field: ident, $fieldty: tt)),* $(,)*}) => { diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs index 7252162e269..4807dc6ff0a 100644 --- a/lightning/src/util/test_utils.rs +++ b/lightning/src/util/test_utils.rs @@ -35,7 +35,7 @@ use crate::ln::msgs::LightningError; use crate::ln::script::ShutdownScript; use crate::offers::invoice::UnsignedBolt12Invoice; use crate::offers::invoice_request::UnsignedInvoiceRequest; -use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; +use crate::onion_message::messenger::{BlindedPathType, DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath}; use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId, RoutingFees}; use crate::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult}; use crate::routing::router::{DefaultRouter, InFlightHtlcs, Path, Route, RouteParameters, RouteHintHop, Router, ScorerAccountingForInFlightHtlcs}; @@ -275,19 +275,10 @@ impl<'a> MessageRouter for TestRouter<'a> { fn create_blinded_paths< T: secp256k1::Signing + secp256k1::Verification >( - &self, recipient: PublicKey, context: MessageContext, - peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()> { - self.router.create_blinded_paths(recipient, context, peers, secp_ctx) - } - - fn create_compact_blinded_paths< - T: secp256k1::Signing + secp256k1::Verification - >( - &self, recipient: PublicKey, context: MessageContext, + &self, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, peers: Vec, secp_ctx: &Secp256k1, ) -> Result, ()> { - self.router.create_compact_blinded_paths(recipient, context, peers, secp_ctx) + self.router.create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx) } } @@ -318,17 +309,10 @@ impl<'a> MessageRouter for TestMessageRouter<'a> { } fn create_blinded_paths( - &self, recipient: PublicKey, context: MessageContext, - peers: Vec, secp_ctx: &Secp256k1, - ) -> Result, ()> { - self.inner.create_blinded_paths(recipient, context, peers, secp_ctx) - } - - fn create_compact_blinded_paths( - &self, recipient: PublicKey, context: MessageContext, + &self, recipient: PublicKey, context: MessageContext, blinded_path: BlindedPathType, peers: Vec, secp_ctx: &Secp256k1, ) -> Result, ()> { - self.inner.create_compact_blinded_paths(recipient, context, peers, secp_ctx) + self.inner.create_blinded_paths(recipient, context, blinded_path, peers, secp_ctx) } } @@ -810,88 +794,88 @@ impl Drop for TestChannelMessageHandler { } impl msgs::ChannelMessageHandler for TestChannelMessageHandler { - fn handle_open_channel(&self, _their_node_id: &PublicKey, msg: &msgs::OpenChannel) { + fn handle_open_channel(&self, _their_node_id: PublicKey, msg: &msgs::OpenChannel) { self.received_msg(wire::Message::OpenChannel(msg.clone())); } - fn handle_accept_channel(&self, _their_node_id: &PublicKey, msg: &msgs::AcceptChannel) { + fn handle_accept_channel(&self, _their_node_id: PublicKey, msg: &msgs::AcceptChannel) { self.received_msg(wire::Message::AcceptChannel(msg.clone())); } - fn handle_funding_created(&self, _their_node_id: &PublicKey, msg: &msgs::FundingCreated) { + fn handle_funding_created(&self, _their_node_id: PublicKey, msg: &msgs::FundingCreated) { self.received_msg(wire::Message::FundingCreated(msg.clone())); } - fn handle_funding_signed(&self, _their_node_id: &PublicKey, msg: &msgs::FundingSigned) { + fn handle_funding_signed(&self, _their_node_id: PublicKey, msg: &msgs::FundingSigned) { self.received_msg(wire::Message::FundingSigned(msg.clone())); } - fn handle_channel_ready(&self, _their_node_id: &PublicKey, msg: &msgs::ChannelReady) { + fn handle_channel_ready(&self, _their_node_id: PublicKey, msg: &msgs::ChannelReady) { self.received_msg(wire::Message::ChannelReady(msg.clone())); } - fn handle_shutdown(&self, _their_node_id: &PublicKey, msg: &msgs::Shutdown) { + fn handle_shutdown(&self, _their_node_id: PublicKey, msg: &msgs::Shutdown) { self.received_msg(wire::Message::Shutdown(msg.clone())); } - fn handle_closing_signed(&self, _their_node_id: &PublicKey, msg: &msgs::ClosingSigned) { + fn handle_closing_signed(&self, _their_node_id: PublicKey, msg: &msgs::ClosingSigned) { self.received_msg(wire::Message::ClosingSigned(msg.clone())); } - fn handle_stfu(&self, _their_node_id: &PublicKey, msg: &msgs::Stfu) { + fn handle_stfu(&self, _their_node_id: PublicKey, msg: &msgs::Stfu) { self.received_msg(wire::Message::Stfu(msg.clone())); } #[cfg(splicing)] - fn handle_splice_init(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceInit) { + fn handle_splice_init(&self, _their_node_id: PublicKey, msg: &msgs::SpliceInit) { self.received_msg(wire::Message::SpliceInit(msg.clone())); } #[cfg(splicing)] - fn handle_splice_ack(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceAck) { + fn handle_splice_ack(&self, _their_node_id: PublicKey, msg: &msgs::SpliceAck) { self.received_msg(wire::Message::SpliceAck(msg.clone())); } #[cfg(splicing)] - fn handle_splice_locked(&self, _their_node_id: &PublicKey, msg: &msgs::SpliceLocked) { + fn handle_splice_locked(&self, _their_node_id: PublicKey, msg: &msgs::SpliceLocked) { self.received_msg(wire::Message::SpliceLocked(msg.clone())); } - fn handle_update_add_htlc(&self, _their_node_id: &PublicKey, msg: &msgs::UpdateAddHTLC) { + fn handle_update_add_htlc(&self, _their_node_id: PublicKey, msg: &msgs::UpdateAddHTLC) { self.received_msg(wire::Message::UpdateAddHTLC(msg.clone())); } - fn handle_update_fulfill_htlc(&self, _their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) { + fn handle_update_fulfill_htlc(&self, _their_node_id: PublicKey, msg: &msgs::UpdateFulfillHTLC) { self.received_msg(wire::Message::UpdateFulfillHTLC(msg.clone())); } - fn handle_update_fail_htlc(&self, _their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) { + fn handle_update_fail_htlc(&self, _their_node_id: PublicKey, msg: &msgs::UpdateFailHTLC) { self.received_msg(wire::Message::UpdateFailHTLC(msg.clone())); } - fn handle_update_fail_malformed_htlc(&self, _their_node_id: &PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { + fn handle_update_fail_malformed_htlc(&self, _their_node_id: PublicKey, msg: &msgs::UpdateFailMalformedHTLC) { self.received_msg(wire::Message::UpdateFailMalformedHTLC(msg.clone())); } - fn handle_commitment_signed(&self, _their_node_id: &PublicKey, msg: &msgs::CommitmentSigned) { + fn handle_commitment_signed(&self, _their_node_id: PublicKey, msg: &msgs::CommitmentSigned) { self.received_msg(wire::Message::CommitmentSigned(msg.clone())); } - fn handle_revoke_and_ack(&self, _their_node_id: &PublicKey, msg: &msgs::RevokeAndACK) { + fn handle_revoke_and_ack(&self, _their_node_id: PublicKey, msg: &msgs::RevokeAndACK) { self.received_msg(wire::Message::RevokeAndACK(msg.clone())); } - fn handle_update_fee(&self, _their_node_id: &PublicKey, msg: &msgs::UpdateFee) { + fn handle_update_fee(&self, _their_node_id: PublicKey, msg: &msgs::UpdateFee) { self.received_msg(wire::Message::UpdateFee(msg.clone())); } - fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &msgs::ChannelUpdate) { + fn handle_channel_update(&self, _their_node_id: PublicKey, _msg: &msgs::ChannelUpdate) { // Don't call `received_msg` here as `TestRoutingMessageHandler` generates these sometimes } - fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) { + fn handle_announcement_signatures(&self, _their_node_id: PublicKey, msg: &msgs::AnnouncementSignatures) { self.received_msg(wire::Message::AnnouncementSignatures(msg.clone())); } - fn handle_channel_reestablish(&self, _their_node_id: &PublicKey, msg: &msgs::ChannelReestablish) { + fn handle_channel_reestablish(&self, _their_node_id: PublicKey, msg: &msgs::ChannelReestablish) { self.received_msg(wire::Message::ChannelReestablish(msg.clone())); } - fn peer_disconnected(&self, their_node_id: &PublicKey) { - assert!(self.connected_peers.lock().unwrap().remove(their_node_id)); + fn peer_disconnected(&self, their_node_id: PublicKey) { + assert!(self.connected_peers.lock().unwrap().remove(&their_node_id)); } - fn peer_connected(&self, their_node_id: &PublicKey, _msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: PublicKey, _msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { assert!(self.connected_peers.lock().unwrap().insert(their_node_id.clone())); // Don't bother with `received_msg` for Init as its auto-generated and we don't want to // bother re-generating the expected Init message in all tests. Ok(()) } - fn handle_error(&self, _their_node_id: &PublicKey, msg: &msgs::ErrorMessage) { + fn handle_error(&self, _their_node_id: PublicKey, msg: &msgs::ErrorMessage) { self.received_msg(wire::Message::Error(msg.clone())); } fn provided_node_features(&self) -> NodeFeatures { channelmanager::provided_node_features(&UserConfig::default()) } - fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_init_features: PublicKey) -> InitFeatures { channelmanager::provided_init_features(&UserConfig::default()) } @@ -899,49 +883,51 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler { Some(vec![self.chain_hash]) } - fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + fn handle_tx_abort(&self, _their_node_id: PublicKey, msg: &msgs::TxAbort) { self.received_msg(wire::Message::TxAbort(msg.clone())); } + + fn message_received(&self) {} } impl events::MessageSendEventsProvider for TestChannelMessageHandler { @@ -1023,14 +1009,14 @@ impl TestRoutingMessageHandler { } } impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { - fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result { + fn handle_node_announcement(&self, _their_node_id: Option, _msg: &msgs::NodeAnnouncement) -> Result { Err(msgs::LightningError { err: "".to_owned(), action: msgs::ErrorAction::IgnoreError }) } - fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result { + fn handle_channel_announcement(&self, _their_node_id: Option, _msg: &msgs::ChannelAnnouncement) -> Result { self.chan_anns_recvd.fetch_add(1, Ordering::AcqRel); Err(msgs::LightningError { err: "".to_owned(), action: msgs::ErrorAction::IgnoreError }) } - fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result { + fn handle_channel_update(&self, _their_node_id: Option, _msg: &msgs::ChannelUpdate) -> Result { self.chan_upds_recvd.fetch_add(1, Ordering::AcqRel); Err(msgs::LightningError { err: "".to_owned(), action: msgs::ErrorAction::IgnoreError }) } @@ -1046,14 +1032,14 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { None } - fn peer_connected(&self, their_node_id: &PublicKey, init_msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { + fn peer_connected(&self, their_node_id: PublicKey, init_msg: &msgs::Init, _inbound: bool) -> Result<(), ()> { if !init_msg.features.supports_gossip_queries() { return Ok(()); } #[allow(unused_mut, unused_assignments)] let mut gossip_start_time = 0; - #[cfg(not(feature = "no-std"))] + #[cfg(feature = "std")] { use std::time::{SystemTime, UNIX_EPOCH}; gossip_start_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs(); @@ -1076,19 +1062,19 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { Ok(()) } - fn handle_reply_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), msgs::LightningError> { + fn handle_reply_channel_range(&self, _their_node_id: PublicKey, _msg: msgs::ReplyChannelRange) -> Result<(), msgs::LightningError> { Ok(()) } - fn handle_reply_short_channel_ids_end(&self, _their_node_id: &PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), msgs::LightningError> { + fn handle_reply_short_channel_ids_end(&self, _their_node_id: PublicKey, _msg: msgs::ReplyShortChannelIdsEnd) -> Result<(), msgs::LightningError> { Ok(()) } - fn handle_query_channel_range(&self, _their_node_id: &PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), msgs::LightningError> { + fn handle_query_channel_range(&self, _their_node_id: PublicKey, _msg: msgs::QueryChannelRange) -> Result<(), msgs::LightningError> { Ok(()) } - fn handle_query_short_channel_ids(&self, _their_node_id: &PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), msgs::LightningError> { + fn handle_query_short_channel_ids(&self, _their_node_id: PublicKey, _msg: msgs::QueryShortChannelIds) -> Result<(), msgs::LightningError> { Ok(()) } @@ -1098,7 +1084,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { features } - fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures { + fn provided_init_features(&self, _their_init_features: PublicKey) -> InitFeatures { let mut features = InitFeatures::empty(); features.set_gossip_queries_optional(); features diff --git a/lightning/src/util/wakers.rs b/lightning/src/util/wakers.rs index e846ef677b3..a01948f3ea1 100644 --- a/lightning/src/util/wakers.rs +++ b/lightning/src/util/wakers.rs @@ -97,11 +97,10 @@ macro_rules! define_callback { ($($bounds: path),*) => { /// A callback which is called when a [`Future`] completes. /// /// Note that this MUST NOT call back into LDK directly, it must instead schedule actions to be -/// taken later. Rust users should use the [`std::future::Future`] implementation for [`Future`] -/// instead. -/// -/// Note that the [`std::future::Future`] implementation may only work for runtimes which schedule -/// futures when they receive a wake, rather than immediately executing them. +/// taken later. +#[cfg_attr(feature = "std", doc = "Rust users should use the [`std::future::Future`] implementation for [`Future`] instead.")] +#[cfg_attr(feature = "std", doc = "")] +#[cfg_attr(feature = "std", doc = "Note that the [`std::future::Future`] implementation may only work for runtimes which schedule futures when they receive a wake, rather than immediately executing them.")] pub trait FutureCallback : $($bounds +)* { /// The method which is called. fn call(&self); diff --git a/msrv-no-dev-deps-check/Cargo.toml b/msrv-no-dev-deps-check/Cargo.toml index 3a4acc675e6..be594f6e5c4 100644 --- a/msrv-no-dev-deps-check/Cargo.toml +++ b/msrv-no-dev-deps-check/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] lightning = { path = "../lightning" } lightning-block-sync = { path = "../lightning-block-sync", features = [ "rest-client", "rpc-client" ] } +lightning-transaction-sync = { path = "../lightning-transaction-sync", features = [ "esplora-async-https", "electrum" ] } lightning-invoice = { path = "../lightning-invoice" } lightning-net-tokio = { path = "../lightning-net-tokio" } lightning-persister = { path = "../lightning-persister" } diff --git a/no-std-check/Cargo.toml b/no-std-check/Cargo.toml index a94939eab48..bc43e63404a 100644 --- a/no-std-check/Cargo.toml +++ b/no-std-check/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [features] -default = ["lightning/no-std"] +default = [] [dependencies] lightning = { path = "../lightning", default-features = false } diff --git a/pending_changelog/3243-remove-balance_msat.txt b/pending_changelog/3243-remove-balance_msat.txt new file mode 100644 index 00000000000..6378bd79054 --- /dev/null +++ b/pending_changelog/3243-remove-balance_msat.txt @@ -0,0 +1 @@ +* The `AvailableBalances::balance_msat` field has been removed in favor of `ChainMonitor::get_claimable_balances`. `ChannelDetails` serialized with versions of LDK >= 0.0.125 will have their `balance_msat` field set to `next_outbound_htlc_limit_msat` when read by versions of LDK prior to 0.0.125 (#3243). diff --git a/rustfmt_excluded_files b/rustfmt_excluded_files index b19cbdd4973..16bc8200088 100644 --- a/rustfmt_excluded_files +++ b/rustfmt_excluded_files @@ -1,107 +1,96 @@ -./lightning-invoice/fuzz/fuzz_targets/serde_data_part.rs -./lightning-invoice/src/de.rs -./lightning-invoice/src/lib.rs -./lightning-invoice/src/payment.rs -./lightning-invoice/src/ser.rs -./lightning-invoice/src/tb.rs -./lightning-invoice/src/utils.rs -./lightning-invoice/tests/ser_de.rs -./lightning/src/blinded_path/message.rs -./lightning/src/blinded_path/mod.rs -./lightning/src/blinded_path/payment.rs -./lightning/src/blinded_path/utils.rs -./lightning/src/chain/chaininterface.rs -./lightning/src/chain/chainmonitor.rs -./lightning/src/chain/channelmonitor.rs -./lightning/src/chain/mod.rs -./lightning/src/chain/onchaintx.rs -./lightning/src/chain/package.rs -./lightning/src/chain/transaction.rs -./lightning/src/crypto/chacha20.rs -./lightning/src/crypto/chacha20poly1305rfc.rs -./lightning/src/crypto/mod.rs -./lightning/src/crypto/poly1305.rs -./lightning/src/crypto/streams.rs -./lightning/src/crypto/utils.rs -./lightning/src/events/bump_transaction.rs -./lightning/src/events/mod.rs -./lightning/src/lib.rs -./lightning/src/ln/async_signer_tests.rs -./lightning/src/ln/blinded_payment_tests.rs -./lightning/src/ln/chan_utils.rs -./lightning/src/ln/chanmon_update_fail_tests.rs -./lightning/src/ln/channel.rs -./lightning/src/ln/channel_id.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/inbound_payment.rs -./lightning/src/ln/invoice_utils.rs -./lightning/src/ln/max_payment_path_len_tests.rs -./lightning/src/ln/mod.rs -./lightning/src/ln/monitor_tests.rs -./lightning/src/ln/msgs.rs -./lightning/src/ln/offers_tests.rs -./lightning/src/ln/onion_payment.rs -./lightning/src/ln/onion_route_tests.rs -./lightning/src/ln/outbound_payment.rs -./lightning/src/ln/payment_tests.rs -./lightning/src/ln/peer_channel_encryptor.rs -./lightning/src/ln/peer_handler.rs -./lightning/src/ln/priv_short_conf_tests.rs -./lightning/src/ln/reload_tests.rs -./lightning/src/ln/reorg_tests.rs -./lightning/src/ln/script.rs -./lightning/src/ln/shutdown_tests.rs -./lightning/src/ln/types.rs -./lightning/src/ln/wire.rs -./lightning/src/offers/invoice.rs -./lightning/src/offers/invoice_error.rs -./lightning/src/offers/invoice_request.rs -./lightning/src/offers/merkle.rs -./lightning/src/offers/mod.rs -./lightning/src/offers/offer.rs -./lightning/src/offers/parse.rs -./lightning/src/offers/payer.rs -./lightning/src/offers/refund.rs -./lightning/src/offers/signer.rs -./lightning/src/offers/test_utils.rs -./lightning/src/onion_message/functional_tests.rs -./lightning/src/onion_message/messenger.rs -./lightning/src/onion_message/mod.rs -./lightning/src/onion_message/offers.rs -./lightning/src/onion_message/packet.rs -./lightning/src/routing/gossip.rs -./lightning/src/routing/mod.rs -./lightning/src/routing/router.rs -./lightning/src/routing/scoring.rs -./lightning/src/routing/test_utils.rs -./lightning/src/routing/utxo.rs -./lightning/src/sync/debug_sync.rs -./lightning/src/sync/fairrwlock.rs -./lightning/src/sync/mod.rs -./lightning/src/sync/nostd_sync.rs -./lightning/src/sync/test_lockorder_checks.rs -./lightning/src/util/atomic_counter.rs -./lightning/src/util/base32.rs -./lightning/src/util/byte_utils.rs -./lightning/src/util/config.rs -./lightning/src/util/errors.rs -./lightning/src/util/fuzz_wrappers.rs -./lightning/src/util/indexed_map.rs -./lightning/src/util/invoice.rs -./lightning/src/util/logger.rs -./lightning/src/util/macro_logger.rs -./lightning/src/util/message_signing.rs -./lightning/src/util/mod.rs -./lightning/src/util/persist.rs -./lightning/src/util/scid_utils.rs -./lightning/src/util/ser.rs -./lightning/src/util/ser_macros.rs -./lightning/src/util/string.rs -./lightning/src/util/test_channel_signer.rs -./lightning/src/util/test_utils.rs -./lightning/src/util/time.rs -./lightning/src/util/transaction_utils.rs -./lightning/src/util/wakers.rs +lightning-invoice/fuzz/fuzz_targets/serde_data_part.rs +lightning-invoice/src/de.rs +lightning-invoice/src/lib.rs +lightning-invoice/src/payment.rs +lightning-invoice/src/ser.rs +lightning-invoice/src/tb.rs +lightning-invoice/src/utils.rs +lightning-invoice/tests/ser_de.rs +lightning/src/blinded_path/message.rs +lightning/src/blinded_path/mod.rs +lightning/src/blinded_path/payment.rs +lightning/src/blinded_path/utils.rs +lightning/src/chain/chaininterface.rs +lightning/src/chain/chainmonitor.rs +lightning/src/chain/channelmonitor.rs +lightning/src/chain/mod.rs +lightning/src/chain/onchaintx.rs +lightning/src/chain/package.rs +lightning/src/chain/transaction.rs +lightning/src/events/bump_transaction.rs +lightning/src/events/mod.rs +lightning/src/lib.rs +lightning/src/ln/async_signer_tests.rs +lightning/src/ln/blinded_payment_tests.rs +lightning/src/ln/chan_utils.rs +lightning/src/ln/chanmon_update_fail_tests.rs +lightning/src/ln/channel.rs +lightning/src/ln/channel_id.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/inbound_payment.rs +lightning/src/ln/invoice_utils.rs +lightning/src/ln/max_payment_path_len_tests.rs +lightning/src/ln/mod.rs +lightning/src/ln/monitor_tests.rs +lightning/src/ln/msgs.rs +lightning/src/ln/offers_tests.rs +lightning/src/ln/onion_payment.rs +lightning/src/ln/onion_route_tests.rs +lightning/src/ln/outbound_payment.rs +lightning/src/ln/payment_tests.rs +lightning/src/ln/peer_channel_encryptor.rs +lightning/src/ln/peer_handler.rs +lightning/src/ln/priv_short_conf_tests.rs +lightning/src/ln/reload_tests.rs +lightning/src/ln/reorg_tests.rs +lightning/src/ln/script.rs +lightning/src/ln/shutdown_tests.rs +lightning/src/ln/types.rs +lightning/src/ln/wire.rs +lightning/src/offers/invoice.rs +lightning/src/offers/invoice_error.rs +lightning/src/offers/invoice_request.rs +lightning/src/offers/merkle.rs +lightning/src/offers/mod.rs +lightning/src/offers/offer.rs +lightning/src/offers/parse.rs +lightning/src/offers/payer.rs +lightning/src/offers/refund.rs +lightning/src/offers/signer.rs +lightning/src/offers/test_utils.rs +lightning/src/onion_message/functional_tests.rs +lightning/src/onion_message/messenger.rs +lightning/src/onion_message/mod.rs +lightning/src/onion_message/offers.rs +lightning/src/onion_message/packet.rs +lightning/src/routing/gossip.rs +lightning/src/routing/mod.rs +lightning/src/routing/router.rs +lightning/src/routing/scoring.rs +lightning/src/routing/test_utils.rs +lightning/src/routing/utxo.rs +lightning/src/util/atomic_counter.rs +lightning/src/util/base32.rs +lightning/src/util/byte_utils.rs +lightning/src/util/config.rs +lightning/src/util/errors.rs +lightning/src/util/fuzz_wrappers.rs +lightning/src/util/indexed_map.rs +lightning/src/util/invoice.rs +lightning/src/util/logger.rs +lightning/src/util/macro_logger.rs +lightning/src/util/message_signing.rs +lightning/src/util/mod.rs +lightning/src/util/persist.rs +lightning/src/util/scid_utils.rs +lightning/src/util/ser.rs +lightning/src/util/ser_macros.rs +lightning/src/util/string.rs +lightning/src/util/test_channel_signer.rs +lightning/src/util/test_utils.rs +lightning/src/util/time.rs +lightning/src/util/transaction_utils.rs +lightning/src/util/wakers.rs