Merge pull request #2599 from Evanfeenstra/peel-onion
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 18 Oct 2023 21:11:52 +0000 (21:11 +0000)
committerGitHub <noreply@github.com>
Wed, 18 Oct 2023 21:11:52 +0000 (21:11 +0000)
public static peel_onion method on OnionMessenger

25 files changed:
.github/workflows/build.yml
ci/ci-tests.sh
fuzz/src/full_stack.rs
fuzz/src/router.rs
lightning-block-sync/src/gossip.rs
lightning-block-sync/src/http.rs
lightning-invoice/src/lib.rs
lightning-net-tokio/src/lib.rs
lightning-rapid-gossip-sync/src/processing.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/priv_short_conf_tests.rs
lightning/src/routing/gossip.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/scid_utils.rs
lightning/src/util/test_utils.rs

index 45bd4d3049123ec422de65ba58a19a4d89821761..00ef76f787e188e0e23fc94b2244bb1cbca8673f 100644 (file)
@@ -51,7 +51,7 @@ jobs:
           shellcheck ci/ci-tests.sh
       - name: Run CI script
         shell: bash # Default on Winblows is powershell
-        run: ./ci/ci-tests.sh
+        run: CI_MINIMIZE_DISK_USAGE=1 ./ci/ci-tests.sh
 
   coverage:
     strategy:
index 6b89a98fddadc2530cce26849acbf6e98d34b480..c24f344f6df2eca76b73190e2d6696d384809cb2 100755 (executable)
@@ -80,6 +80,7 @@ if [ "$RUSTC_MINOR_VERSION" -gt 55 ]; then
        echo -e "\n\nTest Custom Message Macros"
        pushd lightning-custom-message
        cargo test --verbose --color always
+       [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
        popd
 fi
 
@@ -130,17 +131,20 @@ else
        [ "$RUSTC_MINOR_VERSION" -lt 60 ] && cargo update -p memchr --precise "2.5.0" --verbose
        cargo check --verbose --color always
 fi
+[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
 popd
 
 # Test that we can build downstream code with only the "release pins".
 pushd msrv-no-dev-deps-check
 PIN_RELEASE_DEPS
 cargo check
+[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
 popd
 
 if [ -f "$(which arm-none-eabi-gcc)" ]; then
        pushd no-std-check
        cargo build --target=thumbv7m-none-eabi
+       [ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
        popd
 fi
 
index d7167146cac18d90c58d31f617f5af677875bbbf..9ed58dd949d82f6c046ef948bc61bcb4549a6d64 100644 (file)
@@ -772,7 +772,7 @@ mod tests {
                // 030012 - inbound read from peer id 0 of len 18
                // 0147 03000000000000000000000000000000 - message header indicating message length 327
                // 0300fe - inbound read from peer id 0 of len 254
-               // 0020 7500000000000000000000000000000000000000000000000000000000000000 ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679 000000000000c350 0000000000000000 0000000000000162 ffffffffffffffff 0000000000000222 0000000000000000 000000fd 0006 01e3 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 030000000000000000000000000000000000000000000000000000000000000004 - beginning of open_channel message
+               // 0020 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679 000000000000c350 0000000000000000 0000000000000162 ffffffffffffffff 0000000000000222 0000000000000000 000000fd 0006 01e3 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 030000000000000000000000000000000000000000000000000000000000000004 - beginning of open_channel message
                // 030059 - inbound read from peer id 0 of len 89
                // 030000000000000000000000000000000000000000000000000000000000000005 020900000000000000000000000000000000000000000000000000000000000000 01 0000 01021000 03000000000000000000000000000000 - rest of open_channel and mac
                //
@@ -1033,7 +1033,7 @@ mod tests {
                // - client now fails the HTLC backwards as it was unable to extract the payment preimage (CHECK 9 duplicate and CHECK 10)
 
                let logger = Arc::new(TrackingLogger { lines: Mutex::new(HashMap::new()) });
-               super::do_test(&::hex::decode("01000000000000000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000000020300320003000000000000000000000000000000000000000000000000000000000000000203000000000000000000000000000000030012001003000000000000000000000000000000030020001000021aaa0008aaaaaaaaaaaa9aaa030000000000000000000000000000000300120147030000000000000000000000000000000300fe00207500000000000000000000000000000000000000000000000000000000000000ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679000000000000c35000000000000000000000000000000162ffffffffffffffff00000000000002220000000000000000000000fd000601e3030000000000000000000000000000000000000000000000000000000000000001030000000000000000000000000000000000000000000000000000000000000002030000000000000000000000000000000000000000000000000000000000000003030000000000000000000000000000000000000000000000000000000000000004030059030000000000000000000000000000000000000000000000000000000000000005020900000000000000000000000000000000000000000000000000000000000000010000010210000300000000000000000000000000000000fd00fd0300120084030000000000000000000000000000000300940022ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb1819096793d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000c005e020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0150c3000000000000220020ae00000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c000003001200430300000000000000000000000000000003005300243d0000000000000000000000000000000000000000000000000000000000000002080000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000010301320003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000030142000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000030112001001000000000000000000000000000000030120001000021aaa0008aaaaaaaaaaaa9aaa01000000000000000000000000000000050103020000000000000000000000000000000000000000000000000000000000000000c3500003e800fd0301120112010000000000000000000000000000000301ff00210000000000000000000000000000000000000000000000000000000000000e05000000000000016200000000004c4b4000000000000003e800000000000003e80000000203f000050300000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000002000300000000000000000000000000000000000000000000000000000000000003000300000000000000000000000000000000000000000000000000000000000004000300000000000000000000000000000000000000000000000000000000000005000266000000000000000000000000000003012300000000000000000000000000000000000000010000000000000000000000000000000a00fd00fd03011200620100000000000000000000000000000003017200233a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007c0001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000b03011200430100000000000000000000000000000003015300243a000000000000000000000000000000000000000000000000000000000000000267000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000020b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000002640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112004a0100000000000000000000000000000003015a00823a000000000000000000000000000000000000000000000000000000000000000000000000000000ff008888888888888888888888888888888888888888888888888888888888880100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000010000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020a000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c3010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000000000000000000000000000000000000020d00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112002c0100000000000000000000000000000003013c00833a00000000000000000000000000000000000000000000000000000000000000000000000000000100000100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000703001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d00000000000000000000000000000000000000000000000000000000000000000000000000000200000000000b0838ff00000000000000000000000000000000000000000000000000000000000000000003f0000300000000000000000000000000000000000000000000000000000000000005551202030927c00401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff53000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200a4030000000000000000000000000000000300b400843d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007501000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006705000000000000000000000000000000000000000000000000000000000000060300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000020f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd0c007d02000000013a000000000000000000000000000000000000000000000000000000000000000000000000000000800258020000000000002200204b0000000000000000000000000000000000000000000000000000000000000014c00000000000001600142800000000000000000000000000000000000000050000200c005e0200000001730000000000000000000000000000000000000000000000000000000000000000000000000000000001a701000000000000220020b200000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c000007").unwrap(), &(Arc::clone(&logger) as Arc<dyn Logger>));
+               super::do_test(&::hex::decode("01000000000000000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000000020300320003000000000000000000000000000000000000000000000000000000000000000203000000000000000000000000000000030012001003000000000000000000000000000000030020001000021aaa0008aaaaaaaaaaaa9aaa030000000000000000000000000000000300120147030000000000000000000000000000000300fe00206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679000000000000c35000000000000000000000000000000162ffffffffffffffff00000000000002220000000000000000000000fd000601e3030000000000000000000000000000000000000000000000000000000000000001030000000000000000000000000000000000000000000000000000000000000002030000000000000000000000000000000000000000000000000000000000000003030000000000000000000000000000000000000000000000000000000000000004030059030000000000000000000000000000000000000000000000000000000000000005020900000000000000000000000000000000000000000000000000000000000000010000010210000300000000000000000000000000000000fd00fd0300120084030000000000000000000000000000000300940022ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb1819096793d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000210100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000c005e020000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0150c3000000000000220020ae00000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c00000c000003001200430300000000000000000000000000000003005300243d0000000000000000000000000000000000000000000000000000000000000002080000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000010301320003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000030142000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000030112001001000000000000000000000000000000030120001000021aaa0008aaaaaaaaaaaa9aaa01000000000000000000000000000000050103020000000000000000000000000000000000000000000000000000000000000000c3500003e800fd0301120112010000000000000000000000000000000301ff00210000000000000000000000000000000000000000000000000000000000000e05000000000000016200000000004c4b4000000000000003e800000000000003e80000000203f000050300000000000000000000000000000000000000000000000000000000000001000300000000000000000000000000000000000000000000000000000000000002000300000000000000000000000000000000000000000000000000000000000003000300000000000000000000000000000000000000000000000000000000000004000300000000000000000000000000000000000000000000000000000000000005000266000000000000000000000000000003012300000000000000000000000000000000000000010000000000000000000000000000000a00fd00fd03011200620100000000000000000000000000000003017200233a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007c0001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000b03011200430100000000000000000000000000000003015300243a000000000000000000000000000000000000000000000000000000000000000267000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000020b00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006a000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000002640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112004a0100000000000000000000000000000003015a00823a000000000000000000000000000000000000000000000000000000000000000000000000000000ff008888888888888888888888888888888888888888888888888888888888880100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a0000000000000000000000000000000000000000000000000000000000000067000000000000000000000000000000000000000000000000000000000000000265000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d0000000000000000000000000000000000000000000000000000000000000000000000000000010000000000003e80ff00000000000000000000000000000000000000000000000000000000000000000003f00003000000000000000000000000000000000000000000000000000000000000055511020203e80401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020a000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c3010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000b00000000000000000000000000000000000000000000000000000000000000020d00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd03011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a00000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000030112002c0100000000000000000000000000000003013c00833a00000000000000000000000000000000000000000000000000000000000000000000000000000100000100000000000000000000000000000003011200640100000000000000000000000000000003017400843a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000003011200630100000000000000000000000000000003017300853a000000000000000000000000000000000000000000000000000000000000006500000000000000000000000000000000000000000000000000000000000000027100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000703001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000020c000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001200640300000000000000000000000000000003007400843d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032010000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003001205ac030000000000000000000000000000000300ff00803d00000000000000000000000000000000000000000000000000000000000000000000000000000200000000000b0838ff00000000000000000000000000000000000000000000000000000000000000000003f0000300000000000000000000000000000000000000000000000000000000000005551202030927c00401a0060800000e00000100000a00000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0300c1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff53000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000fd03001200a4030000000000000000000000000000000300b400843d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007501000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006705000000000000000000000000000000000000000000000000000000000000060300000000000000000000000000000003001200630300000000000000000000000000000003007300853d000000000000000000000000000000000000000000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000020f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000700fd00fd0c007d02000000013a000000000000000000000000000000000000000000000000000000000000000000000000000000800258020000000000002200204b0000000000000000000000000000000000000000000000000000000000000014c00000000000001600142800000000000000000000000000000000000000050000200c005e0200000001730000000000000000000000000000000000000000000000000000000000000000000000000000000001a701000000000000220020b200000000000000000000000000000000000000000000000000000000000000000000000c00000c00000c00000c00000c000007").unwrap(), &(Arc::clone(&logger) as Arc<dyn Logger>));
 
                let log_entries = logger.lines.lock().unwrap();
                assert_eq!(log_entries.get(&("lightning::ln::peer_handler".to_string(), "Handling SendAcceptChannel event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000002 for channel ff4f00f805273c1b203bb5ebf8436bfde57b3be8c2f5e95d9491dbb181909679".to_string())), Some(&1)); // 1
index 7f4e7ad401904716cbe01b3a258a3e752a43128a..c9ceea3d0b3d196169d47a996f4e4a47237098aa 100644 (file)
@@ -7,9 +7,9 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::script::Builder;
 use bitcoin::blockdata::transaction::TxOut;
-use bitcoin::hash_types::BlockHash;
 
 use lightning::blinded_path::{BlindedHop, BlindedPath};
 use lightning::chain::transaction::OutPoint;
@@ -89,7 +89,7 @@ struct FuzzChainSource<'a, 'b, Out: test_logger::Output> {
        net_graph: &'a NetworkGraph<&'b test_logger::TestLogger<Out>>,
 }
 impl<Out: test_logger::Output> UtxoLookup for FuzzChainSource<'_, '_, Out> {
-       fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
+       fn get_utxo(&self, _chain_hash: &ChainHash, _short_channel_id: u64) -> UtxoResult {
                let input_slice = self.input.get_slice(2);
                if input_slice.is_none() { return UtxoResult::Sync(Err(UtxoLookupError::UnknownTx)); }
                let input_slice = input_slice.unwrap();
index 37f4268513f45ec2558a0d8f0635370c37e2d5f0..3b6e9f68376c9f00fa6427552bb87e7b6653cb16 100644 (file)
@@ -5,6 +5,7 @@
 use crate::{AsyncBlockSourceResult, BlockData, BlockSource, BlockSourceError};
 
 use bitcoin::blockdata::block::Block;
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::transaction::{TxOut, OutPoint};
 use bitcoin::hash_types::BlockHash;
 
@@ -302,7 +303,7 @@ impl<S: FutureSpawner,
        CMH::Target: CustomMessageHandler,
        NS::Target: NodeSigner,
 {
-       fn get_utxo(&self, _genesis_hash: &BlockHash, short_channel_id: u64) -> UtxoResult {
+       fn get_utxo(&self, _chain_hash: &ChainHash, short_channel_id: u64) -> UtxoResult {
                let res = UtxoFuture::new();
                let fut = res.clone();
                let source = self.source.clone();
index a3935edf5cb6e9880217196112d8f4ead5bacd57..58d66686f0107e311e90bb2fc373603b723806bc 100644 (file)
@@ -511,21 +511,19 @@ mod endpoint_tests {
 
        #[test]
        fn convert_to_socket_addrs() {
-               let endpoint = HttpEndpoint::for_host("foo.com".into());
+               let endpoint = HttpEndpoint::for_host("localhost".into());
                let host = endpoint.host();
                let port = endpoint.port();
 
                use std::net::ToSocketAddrs;
                match (&endpoint).to_socket_addrs() {
                        Err(e) => panic!("Unexpected error: {:?}", e),
-                       Ok(mut socket_addrs) => {
-                               match socket_addrs.next() {
-                                       None => panic!("Expected socket address"),
-                                       Some(addr) => {
-                                               assert_eq!(addr, (host, port).to_socket_addrs().unwrap().next().unwrap());
-                                               assert!(socket_addrs.next().is_none());
-                                       }
+                       Ok(socket_addrs) => {
+                               let mut std_addrs = (host, port).to_socket_addrs().unwrap();
+                               for addr in socket_addrs {
+                                       assert_eq!(addr, std_addrs.next().unwrap());
                                }
+                               assert!(std_addrs.next().is_none());
                        }
                }
        }
index 9695d79036ecc6a776e9ab10e340f0a94a7463d1..d953795cf8e061157f1c69e9c5bc5eae2b743ca6 100644 (file)
@@ -504,7 +504,7 @@ pub struct Bolt11InvoiceSignature(pub RecoverableSignature);
 
 impl PartialOrd for Bolt11InvoiceSignature {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-               self.0.serialize_compact().1.partial_cmp(&other.0.serialize_compact().1)
+               Some(self.cmp(other))
        }
 }
 
index 5527d85adf6f819e0b02e3ad05e18cc7c4426ae6..bac18b2b398cac33ebbb9523fc0a2811da914b75 100644 (file)
@@ -630,7 +630,7 @@ mod tests {
                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 { InitFeatures::empty() }
-               fn get_genesis_hashes(&self) -> Option<Vec<ChainHash>> {
+               fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
                        Some(vec![ChainHash::using_genesis_block(Network::Testnet)])
                }
        }
index fca318a5fa5f8cfac735ff8d3880819e8b6d93a0..d54f1329798b0b986363f67f4c86b91c59f0d929 100644 (file)
@@ -2,7 +2,7 @@ use core::cmp::max;
 use core::ops::Deref;
 use core::sync::atomic::Ordering;
 
-use bitcoin::BlockHash;
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::secp256k1::PublicKey;
 
 use lightning::ln::msgs::{
@@ -67,9 +67,9 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                        return Err(DecodeError::UnknownVersion.into());
                }
 
-               let chain_hash: BlockHash = Readable::read(read_cursor)?;
-               let ng_genesis_hash = self.network_graph.get_genesis_hash();
-               if chain_hash != ng_genesis_hash {
+               let chain_hash: ChainHash = Readable::read(read_cursor)?;
+               let ng_chain_hash = self.network_graph.get_chain_hash();
+               if chain_hash != ng_chain_hash {
                        return Err(
                                LightningError {
                                        err: "Rapid Gossip Sync data's chain hash does not match the network graph's".to_owned(),
index a61a8de82debecd5906c0ee95bdcdb420aae48f4..ef5bf6895a81e2fe2d5e33d47297b579dee15b97 100644 (file)
@@ -7,6 +7,7 @@
 // You may not use this file except in accordance with one or both of these
 // licenses.
 
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::script::{Script,Builder};
 use bitcoin::blockdata::transaction::{Transaction, EcdsaSighashType};
 use bitcoin::util::sighash;
@@ -2661,7 +2662,7 @@ impl<SP: Deref> Channel<SP> where
        /// and the channel is now usable (and public), this may generate an announcement_signatures to
        /// reply with.
        pub fn channel_ready<NS: Deref, L: Deref>(
-               &mut self, msg: &msgs::ChannelReady, node_signer: &NS, genesis_block_hash: BlockHash,
+               &mut self, msg: &msgs::ChannelReady, node_signer: &NS, chain_hash: ChainHash,
                user_config: &UserConfig, best_block: &BestBlock, logger: &L
        ) -> Result<Option<msgs::AnnouncementSignatures>, ChannelError>
        where
@@ -2732,7 +2733,7 @@ impl<SP: Deref> Channel<SP> where
 
                log_info!(logger, "Received channel_ready from peer for channel {}", &self.context.channel_id());
 
-               Ok(self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block.height(), logger))
+               Ok(self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height(), logger))
        }
 
        pub fn update_add_htlc<F, FE: Deref, L: Deref>(
@@ -3766,7 +3767,7 @@ impl<SP: Deref> Channel<SP> where
        /// successfully and we should restore normal operation. Returns messages which should be sent
        /// to the remote side.
        pub fn monitor_updating_restored<L: Deref, NS: Deref>(
-               &mut self, logger: &L, node_signer: &NS, genesis_block_hash: BlockHash,
+               &mut self, logger: &L, node_signer: &NS, chain_hash: ChainHash,
                user_config: &UserConfig, best_block_height: u32
        ) -> MonitorRestoreUpdates
        where
@@ -3807,7 +3808,7 @@ impl<SP: Deref> Channel<SP> where
                        })
                } else { None };
 
-               let announcement_sigs = self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block_height, logger);
+               let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
 
                let mut accepted_htlcs = Vec::new();
                mem::swap(&mut accepted_htlcs, &mut self.context.monitor_pending_forwards);
@@ -3977,7 +3978,7 @@ impl<SP: Deref> Channel<SP> where
        /// [`super::channelmanager::ChannelManager::force_close_all_channels_without_broadcasting_txn`].
        pub fn channel_reestablish<L: Deref, NS: Deref>(
                &mut self, msg: &msgs::ChannelReestablish, logger: &L, node_signer: &NS,
-               genesis_block_hash: BlockHash, user_config: &UserConfig, best_block: &BestBlock
+               chain_hash: ChainHash, user_config: &UserConfig, best_block: &BestBlock
        ) -> Result<ReestablishResponses, ChannelError>
        where
                L::Target: Logger,
@@ -4036,7 +4037,7 @@ impl<SP: Deref> Channel<SP> where
 
                let shutdown_msg = self.get_outbound_shutdown();
 
-               let announcement_sigs = self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, best_block.height(), logger);
+               let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block.height(), logger);
 
                if self.context.channel_state & (ChannelState::FundingSent as u32) == ChannelState::FundingSent as u32 {
                        // If we're waiting on a monitor update, we shouldn't re-send any channel_ready's.
@@ -4813,7 +4814,7 @@ impl<SP: Deref> Channel<SP> where
        /// In the second, we simply return an Err indicating we need to be force-closed now.
        pub fn transactions_confirmed<NS: Deref, L: Deref>(
                &mut self, block_hash: &BlockHash, height: u32, txdata: &TransactionData,
-               genesis_block_hash: BlockHash, node_signer: &NS, user_config: &UserConfig, logger: &L
+               chain_hash: ChainHash, node_signer: &NS, user_config: &UserConfig, logger: &L
        ) -> Result<(Option<msgs::ChannelReady>, Option<msgs::AnnouncementSignatures>), ClosureReason>
        where
                NS::Target: NodeSigner,
@@ -4874,7 +4875,7 @@ impl<SP: Deref> Channel<SP> where
                                        // may have already happened for this block).
                                        if let Some(channel_ready) = self.check_get_channel_ready(height) {
                                                log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
-                                               let announcement_sigs = self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, height, logger);
+                                               let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
                                                msgs = (Some(channel_ready), announcement_sigs);
                                        }
                                }
@@ -4901,19 +4902,19 @@ impl<SP: Deref> Channel<SP> where
        /// May return some HTLCs (and their payment_hash) which have timed out and should be failed
        /// back.
        pub fn best_block_updated<NS: Deref, L: Deref>(
-               &mut self, height: u32, highest_header_time: u32, genesis_block_hash: BlockHash,
+               &mut self, height: u32, highest_header_time: u32, chain_hash: ChainHash,
                node_signer: &NS, user_config: &UserConfig, logger: &L
        ) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
        where
                NS::Target: NodeSigner,
                L::Target: Logger
        {
-               self.do_best_block_updated(height, highest_header_time, Some((genesis_block_hash, node_signer, user_config)), logger)
+               self.do_best_block_updated(height, highest_header_time, Some((chain_hash, node_signer, user_config)), logger)
        }
 
        fn do_best_block_updated<NS: Deref, L: Deref>(
                &mut self, height: u32, highest_header_time: u32,
-               genesis_node_signer: Option<(BlockHash, &NS, &UserConfig)>, logger: &L
+               chain_node_signer: Option<(ChainHash, &NS, &UserConfig)>, logger: &L
        ) -> Result<(Option<msgs::ChannelReady>, Vec<(HTLCSource, PaymentHash)>, Option<msgs::AnnouncementSignatures>), ClosureReason>
        where
                NS::Target: NodeSigner,
@@ -4939,8 +4940,8 @@ impl<SP: Deref> Channel<SP> where
                self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
 
                if let Some(channel_ready) = self.check_get_channel_ready(height) {
-                       let announcement_sigs = if let Some((genesis_block_hash, node_signer, user_config)) = genesis_node_signer {
-                               self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, height, logger)
+                       let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
+                               self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
                        } else { None };
                        log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
                        return Ok((Some(channel_ready), timed_out_htlcs, announcement_sigs));
@@ -4980,8 +4981,8 @@ impl<SP: Deref> Channel<SP> where
                        return Err(ClosureReason::FundingTimedOut);
                }
 
-               let announcement_sigs = if let Some((genesis_block_hash, node_signer, user_config)) = genesis_node_signer {
-                       self.get_announcement_sigs(node_signer, genesis_block_hash, user_config, height, logger)
+               let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
+                       self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
                } else { None };
                Ok((None, timed_out_htlcs, announcement_sigs))
        }
@@ -4998,7 +4999,7 @@ impl<SP: Deref> Channel<SP> where
                        // larger. If we don't know that time has moved forward, we can just set it to the last
                        // time we saw and it will be ignored.
                        let best_time = self.context.update_time_counter;
-                       match self.do_best_block_updated(reorg_height, best_time, None::<(BlockHash, &&NodeSigner, &UserConfig)>, logger) {
+                       match self.do_best_block_updated(reorg_height, best_time, None::<(ChainHash, &&NodeSigner, &UserConfig)>, logger) {
                                Ok((channel_ready, timed_out_htlcs, announcement_sigs)) => {
                                        assert!(channel_ready.is_none(), "We can't generate a funding with 0 confirmations?");
                                        assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
@@ -5028,7 +5029,7 @@ impl<SP: Deref> Channel<SP> where
        ///
        /// [`ChannelReady`]: crate::ln::msgs::ChannelReady
        fn get_channel_announcement<NS: Deref>(
-               &self, node_signer: &NS, chain_hash: BlockHash, user_config: &UserConfig,
+               &self, node_signer: &NS, chain_hash: ChainHash, user_config: &UserConfig,
        ) -> Result<msgs::UnsignedChannelAnnouncement, ChannelError> where NS::Target: NodeSigner {
                if !self.context.config.announced_channel {
                        return Err(ChannelError::Ignore("Channel is not available for public announcements".to_owned()));
@@ -5059,7 +5060,7 @@ impl<SP: Deref> Channel<SP> where
        }
 
        fn get_announcement_sigs<NS: Deref, L: Deref>(
-               &mut self, node_signer: &NS, genesis_block_hash: BlockHash, user_config: &UserConfig,
+               &mut self, node_signer: &NS, chain_hash: ChainHash, user_config: &UserConfig,
                best_block_height: u32, logger: &L
        ) -> Option<msgs::AnnouncementSignatures>
        where
@@ -5084,7 +5085,7 @@ impl<SP: Deref> Channel<SP> where
                }
 
                log_trace!(logger, "Creating an announcement_signatures message for channel {}", &self.context.channel_id());
-               let announcement = match self.get_channel_announcement(node_signer, genesis_block_hash, user_config) {
+               let announcement = match self.get_channel_announcement(node_signer, chain_hash, user_config) {
                        Ok(a) => a,
                        Err(e) => {
                                log_trace!(logger, "{:?}", e);
@@ -5158,7 +5159,7 @@ impl<SP: Deref> Channel<SP> where
        /// channel_announcement message which we can broadcast and storing our counterparty's
        /// signatures for later reconstruction/rebroadcast of the channel_announcement.
        pub fn announcement_signatures<NS: Deref>(
-               &mut self, node_signer: &NS, chain_hash: BlockHash, best_block_height: u32,
+               &mut self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32,
                msg: &msgs::AnnouncementSignatures, user_config: &UserConfig
        ) -> Result<msgs::ChannelAnnouncement, ChannelError> where NS::Target: NodeSigner {
                let announcement = self.get_channel_announcement(node_signer, chain_hash, user_config)?;
@@ -5188,7 +5189,7 @@ impl<SP: Deref> Channel<SP> where
        /// Gets a signed channel_announcement for this channel, if we previously received an
        /// announcement_signatures from our counterparty.
        pub fn get_signed_channel_announcement<NS: Deref>(
-               &self, node_signer: &NS, chain_hash: BlockHash, best_block_height: u32, user_config: &UserConfig
+               &self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32, user_config: &UserConfig
        ) -> Option<msgs::ChannelAnnouncement> where NS::Target: NodeSigner {
                if self.context.funding_tx_confirmation_height == 0 || self.context.funding_tx_confirmation_height + 5 > best_block_height {
                        return None;
@@ -5998,7 +5999,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
        /// not of our ability to open any channel at all. Thus, on error, we should first call this
        /// and see if we get a new `OpenChannel` message, otherwise the channel is failed.
        pub(crate) fn maybe_handle_error_without_close<F: Deref>(
-               &mut self, chain_hash: BlockHash, fee_estimator: &LowerBoundedFeeEstimator<F>
+               &mut self, chain_hash: ChainHash, fee_estimator: &LowerBoundedFeeEstimator<F>
        ) -> Result<msgs::OpenChannel, ()>
        where
                F::Target: FeeEstimator
@@ -6030,7 +6031,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
                Ok(self.get_open_channel(chain_hash))
        }
 
-       pub fn get_open_channel(&self, chain_hash: BlockHash) -> msgs::OpenChannel {
+       pub fn get_open_channel(&self, chain_hash: ChainHash) -> msgs::OpenChannel {
                if !self.context.is_outbound() {
                        panic!("Tried to open a channel for an inbound channel?");
                }
@@ -7633,9 +7634,9 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
 #[cfg(test)]
 mod tests {
        use std::cmp;
+       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::blockdata::script::{Script, Builder};
        use bitcoin::blockdata::transaction::{Transaction, TxOut};
-       use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::blockdata::opcodes;
        use bitcoin::network::constants::Network;
        use hex;
@@ -7779,7 +7780,7 @@ mod tests {
                // Now change the fee so we can check that the fee in the open_channel message is the
                // same as the old fee.
                fee_est.fee_est = 500;
-               let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network));
                assert_eq!(open_channel_msg.feerate_per_kw, original_fee);
        }
 
@@ -7805,7 +7806,7 @@ mod tests {
 
                // Create Node B's channel by receiving Node A's open_channel message
                // Make sure A's dust limit is as we expect.
-               let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network));
                let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
                let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false).unwrap();
 
@@ -7923,7 +7924,7 @@ mod tests {
                let seed = [42; 32];
                let network = Network::Testnet;
                let best_block = BestBlock::from_network(network);
-               let chain_hash = best_block.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(network);
                let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
 
                // Go through the flow of opening a channel between two nodes.
@@ -8003,7 +8004,7 @@ mod tests {
                let chan_2_value_msat = chan_2.context.channel_value_satoshis * 1000;
                assert_eq!(chan_2.context.holder_max_htlc_value_in_flight_msat, (chan_2_value_msat as f64 * 0.99) as u64);
 
-               let chan_1_open_channel_msg = chan_1.get_open_channel(genesis_block(network).header.block_hash());
+               let chan_1_open_channel_msg = chan_1.get_open_channel(ChainHash::using_genesis_block(network));
 
                // Test that `InboundV1Channel::new` creates a channel with the correct value for
                // `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value,
@@ -8084,7 +8085,7 @@ mod tests {
                let expected_outbound_selected_chan_reserve = cmp::max(MIN_THEIR_CHAN_RESERVE_SATOSHIS, (chan.context.channel_value_satoshis as f64 * outbound_selected_channel_reserve_perc) as u64);
                assert_eq!(chan.context.holder_selected_channel_reserve_satoshis, expected_outbound_selected_chan_reserve);
 
-               let chan_open_channel_msg = chan.get_open_channel(genesis_block(network).header.block_hash());
+               let chan_open_channel_msg = chan.get_open_channel(ChainHash::using_genesis_block(network));
                let mut inbound_node_config = UserConfig::default();
                inbound_node_config.channel_handshake_config.their_channel_reserve_proportional_millionths = (inbound_selected_channel_reserve_perc * 1_000_000.0) as u32;
 
@@ -8110,7 +8111,7 @@ mod tests {
                let seed = [42; 32];
                let network = Network::Testnet;
                let best_block = BestBlock::from_network(network);
-               let chain_hash = genesis_block(network).header.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(network);
                let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
 
                // Create Node A's channel pointing to Node B's pubkey
@@ -8120,7 +8121,7 @@ mod tests {
 
                // Create Node B's channel by receiving Node A's open_channel message
                // Make sure A's dust limit is as we expect.
-               let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network));
                let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
                let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, /*is_0conf=*/false).unwrap();
 
@@ -8957,7 +8958,7 @@ mod tests {
                let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
                channel_type_features.set_zero_conf_required();
 
-               let mut open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
+               let mut open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network));
                open_channel_msg.channel_type = Some(channel_type_features);
                let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
                let res = InboundV1Channel::<&TestKeysInterface>::new(&feeest, &&keys_provider, &&keys_provider,
@@ -9000,7 +9001,7 @@ mod tests {
                        &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42
                ).unwrap();
 
-               let open_channel_msg = channel_a.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network));
                let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
                        &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
                        &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config),
@@ -9038,7 +9039,7 @@ mod tests {
                ).unwrap();
 
                // Set `channel_type` to `None` to force the implicit feature negotiation.
-               let mut open_channel_msg = channel_a.get_open_channel(genesis_block(network).header.block_hash());
+               let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network));
                open_channel_msg.channel_type = None;
 
                // Since A supports both `static_remote_key` and `option_anchors`, but B only accepts
@@ -9083,7 +9084,7 @@ mod tests {
                        &channelmanager::provided_init_features(&config), 10000000, 100000, 42, &config, 0, 42
                ).unwrap();
 
-               let mut open_channel_msg = channel_a.get_open_channel(genesis_block(network).header.block_hash());
+               let mut open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network));
                open_channel_msg.channel_type = Some(simple_anchors_channel_type.clone());
 
                let res = InboundV1Channel::<&TestKeysInterface>::new(
@@ -9102,7 +9103,7 @@ mod tests {
                        10000000, 100000, 42, &config, 0, 42
                ).unwrap();
 
-               let open_channel_msg = channel_a.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = channel_a.get_open_channel(ChainHash::using_genesis_block(network));
 
                let channel_b = InboundV1Channel::<&TestKeysInterface>::new(
                        &fee_estimator, &&keys_provider, &&keys_provider, node_id_a,
@@ -9127,7 +9128,7 @@ mod tests {
                let seed = [42; 32];
                let network = Network::Testnet;
                let best_block = BestBlock::from_network(network);
-               let chain_hash = genesis_block(network).header.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(network);
                let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
 
                let mut config = UserConfig::default();
@@ -9151,7 +9152,7 @@ mod tests {
                        42,
                ).unwrap();
 
-               let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
+               let open_channel_msg = node_a_chan.get_open_channel(ChainHash::using_genesis_block(network));
                let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
                let mut node_b_chan = InboundV1Channel::<&TestKeysInterface>::new(
                        &feeest,
index 24ca65af00805a4463c6cac1c155a39f1b30cdf9..a4079734241e4b80f929a10514f885846ee8b816 100644 (file)
@@ -19,7 +19,7 @@
 
 use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::Transaction;
-use bitcoin::blockdata::constants::{genesis_block, ChainHash};
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::network::constants::Network;
 
 use bitcoin::hashes::Hash;
@@ -1018,7 +1018,7 @@ where
        L::Target: Logger,
 {
        default_configuration: UserConfig,
-       genesis_hash: BlockHash,
+       chain_hash: ChainHash,
        fee_estimator: LowerBoundedFeeEstimator<F>,
        chain_monitor: M,
        tx_broadcaster: T,
@@ -2012,7 +2012,7 @@ macro_rules! emit_channel_ready_event {
 macro_rules! handle_monitor_update_completion {
        ($self: ident, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
                let mut updates = $chan.monitor_updating_restored(&$self.logger,
-                       &$self.node_signer, $self.genesis_hash, &$self.default_configuration,
+                       &$self.node_signer, $self.chain_hash, &$self.default_configuration,
                        $self.best_block.read().unwrap().height());
                let counterparty_node_id = $chan.context.get_counterparty_node_id();
                let channel_update = if updates.channel_ready.is_some() && $chan.context.is_usable() {
@@ -2258,7 +2258,7 @@ where
                let expanded_inbound_key = inbound_payment::ExpandedKey::new(&inbound_pmt_key_material);
                ChannelManager {
                        default_configuration: config.clone(),
-                       genesis_hash: genesis_block(params.network).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(params.network),
                        fee_estimator: LowerBoundedFeeEstimator::new(fee_est),
                        chain_monitor,
                        tx_broadcaster,
@@ -2317,7 +2317,7 @@ where
                        if cfg!(fuzzing) { // fuzzing chacha20 doesn't use the key at all so we always get the same alias
                                outbound_scid_alias += 1;
                        } else {
-                               outbound_scid_alias = fake_scid::Namespace::OutboundAlias.get_fake_scid(height, &self.genesis_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
+                               outbound_scid_alias = fake_scid::Namespace::OutboundAlias.get_fake_scid(height, &self.chain_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
                        }
                        if outbound_scid_alias != 0 && self.outbound_scid_aliases.lock().unwrap().insert(outbound_scid_alias) {
                                break;
@@ -2387,7 +2387,7 @@ where
                                },
                        }
                };
-               let res = channel.get_open_channel(self.genesis_hash.clone());
+               let res = channel.get_open_channel(self.chain_hash);
 
                let temporary_channel_id = channel.context.channel_id();
                match peer_state.channel_by_id.entry(temporary_channel_id) {
@@ -2616,6 +2616,8 @@ where
                                        // it does not exist for this peer. Either way, we can attempt to force-close it.
                                        //
                                        // An appropriate error will be returned for non-existence of the channel if that's the case.
+                                       mem::drop(peer_state_lock);
+                                       mem::drop(per_peer_state);
                                        return self.force_close_channel_with_peer(&channel_id, counterparty_node_id, None, false).map(|_| ())
                                },
                        }
@@ -2938,7 +2940,7 @@ where
                // payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
                // channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
                let current_height: u32 = self.best_block.read().unwrap().height();
-               if (outgoing_cltv_value as u64) <= current_height as u64 + HTLC_FAIL_BACK_BUFFER as u64 + 1 {
+               if cltv_expiry <= current_height + HTLC_FAIL_BACK_BUFFER + 1 {
                        let mut err_data = Vec::with_capacity(12);
                        err_data.extend_from_slice(&amt_msat.to_be_bytes());
                        err_data.extend_from_slice(&current_height.to_be_bytes());
@@ -3101,8 +3103,8 @@ where
                                        // Note that this is likely a timing oracle for detecting whether an scid is a
                                        // phantom or an intercept.
                                        if (self.default_configuration.accept_intercept_htlcs &&
-                                               fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, outgoing_scid, &self.genesis_hash)) ||
-                                               fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, outgoing_scid, &self.genesis_hash)
+                                               fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, outgoing_scid, &self.chain_hash)) ||
+                                               fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, outgoing_scid, &self.chain_hash)
                                        {
                                                None
                                        } else {
@@ -3330,7 +3332,7 @@ where
                };
 
                let unsigned = msgs::UnsignedChannelUpdate {
-                       chain_hash: self.genesis_hash,
+                       chain_hash: self.chain_hash,
                        short_channel_id,
                        timestamp: chan.context.get_update_time_counter(),
                        flags: (!were_node_one) as u8 | ((!enabled as u8) << 1),
@@ -4001,7 +4003,7 @@ where
                for channel_id in channel_ids {
                        if !peer_state.has_channel(channel_id) {
                                return Err(APIError::ChannelUnavailable {
-                                       err: format!("Channel with ID {} was not found for the passed counterparty_node_id {}", channel_id, counterparty_node_id),
+                                       err: format!("Channel with id {} not found for the passed counterparty node_id {}", channel_id, counterparty_node_id),
                                });
                        };
                }
@@ -4112,7 +4114,7 @@ where
                                                next_hop_channel_id, next_node_id)
                                }),
                                None => return Err(APIError::ChannelUnavailable {
-                                       err: format!("Channel with id {} not found for the passed counterparty node_id {}.",
+                                       err: format!("Channel with id {} not found for the passed counterparty node_id {}",
                                                next_hop_channel_id, next_node_id)
                                })
                        }
@@ -4248,7 +4250,7 @@ where
                                                                                }
                                                                                if let PendingHTLCRouting::Forward { onion_packet, .. } = routing {
                                                                                        let phantom_pubkey_res = self.node_signer.get_node_id(Recipient::PhantomNode);
-                                                                                       if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.genesis_hash) {
+                                                                                       if phantom_pubkey_res.is_ok() && fake_scid::is_valid_phantom(&self.fake_scid_rand_bytes, short_chan_id, &self.chain_hash) {
                                                                                                let phantom_shared_secret = self.node_signer.ecdh(Recipient::PhantomNode, &onion_packet.public_key.unwrap(), None).unwrap().secret_bytes();
                                                                                                let next_hop = match onion_utils::decode_next_payment_hop(
                                                                                                        phantom_shared_secret, &onion_packet.hop_data, onion_packet.hmac,
@@ -5874,7 +5876,7 @@ where
        fn internal_open_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannel) -> Result<(), MsgHandleErrInternal> {
                // Note that the ChannelManager is NOT re-persisted on disk after this, so any changes are
                // likely to be lost on restart!
-               if msg.chain_hash != self.genesis_hash {
+               if msg.chain_hash != self.chain_hash {
                        return Err(MsgHandleErrInternal::send_err_msg_no_close("Unknown genesis block hash".to_owned(), msg.temporary_channel_id.clone()));
                }
 
@@ -6139,7 +6141,7 @@ where
                        hash_map::Entry::Occupied(mut chan_phase_entry) => {
                                if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
                                        let announcement_sigs_opt = try_chan_phase_entry!(self, chan.channel_ready(&msg, &self.node_signer,
-                                               self.genesis_hash.clone(), &self.default_configuration, &self.best_block.read().unwrap(), &self.logger), chan_phase_entry);
+                                               self.chain_hash, &self.default_configuration, &self.best_block.read().unwrap(), &self.logger), chan_phase_entry);
                                        if let Some(announcement_sigs) = announcement_sigs_opt {
                                                log_trace!(self.logger, "Sending announcement_signatures for channel {}", chan.context.channel_id());
                                                peer_state.pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
@@ -6516,7 +6518,7 @@ where
                                                },
                                                hash_map::Entry::Vacant(entry) => {
                                                        if !is_our_scid && forward_info.incoming_amt_msat.is_some() &&
-                                                          fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, scid, &self.genesis_hash)
+                                                          fake_scid::is_valid_intercept(&self.fake_scid_rand_bytes, scid, &self.chain_hash)
                                                        {
                                                                let intercept_id = InterceptId(Sha256::hash(&forward_info.incoming_shared_secret).into_inner());
                                                                let mut pending_intercepts = self.pending_intercepted_htlcs.lock().unwrap();
@@ -6709,7 +6711,7 @@ where
 
                                        peer_state.pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
                                                msg: try_chan_phase_entry!(self, chan.announcement_signatures(
-                                                       &self.node_signer, self.genesis_hash.clone(), self.best_block.read().unwrap().height(),
+                                                       &self.node_signer, self.chain_hash, self.best_block.read().unwrap().height(),
                                                        msg, &self.default_configuration
                                                ), chan_phase_entry),
                                                // Note that announcement_signatures fails if the channel cannot be announced,
@@ -6797,7 +6799,7 @@ where
                                                // freed HTLCs to fail backwards. If in the future we no longer drop pending
                                                // add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
                                                let responses = try_chan_phase_entry!(self, chan.channel_reestablish(
-                                                       msg, &self.logger, &self.node_signer, self.genesis_hash,
+                                                       msg, &self.logger, &self.node_signer, self.chain_hash,
                                                        &self.default_configuration, &*self.best_block.read().unwrap()), chan_phase_entry);
                                                let mut channel_update = None;
                                                if let Some(msg) = responses.shutdown_msg {
@@ -7177,7 +7179,7 @@ where
                let best_block_height = self.best_block.read().unwrap().height();
                let short_to_chan_info = self.short_to_chan_info.read().unwrap();
                loop {
-                       let scid_candidate = fake_scid::Namespace::Phantom.get_fake_scid(best_block_height, &self.genesis_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
+                       let scid_candidate = fake_scid::Namespace::Phantom.get_fake_scid(best_block_height, &self.chain_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
                        // Ensure the generated scid doesn't conflict with a real channel.
                        match short_to_chan_info.get(&scid_candidate) {
                                Some(_) => continue,
@@ -7207,7 +7209,7 @@ where
                let best_block_height = self.best_block.read().unwrap().height();
                let short_to_chan_info = self.short_to_chan_info.read().unwrap();
                loop {
-                       let scid_candidate = fake_scid::Namespace::Intercept.get_fake_scid(best_block_height, &self.genesis_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
+                       let scid_candidate = fake_scid::Namespace::Intercept.get_fake_scid(best_block_height, &self.chain_hash, &self.fake_scid_rand_bytes, &self.entropy_source);
                        // Ensure the generated scid doesn't conflict with a real channel.
                        if short_to_chan_info.contains_key(&scid_candidate) { continue }
                        return scid_candidate
@@ -7470,7 +7472,7 @@ where
                        *best_block = BestBlock::new(header.prev_blockhash, new_height)
                }
 
-               self.do_chain_event(Some(new_height), |channel| channel.best_block_updated(new_height, header.time, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger));
+               self.do_chain_event(Some(new_height), |channel| channel.best_block_updated(new_height, header.time, self.chain_hash, &self.node_signer, &self.default_configuration, &self.logger));
        }
 }
 
@@ -7496,13 +7498,13 @@ where
                let _persistence_guard =
                        PersistenceNotifierGuard::optionally_notify_skipping_background_events(
                                self, || -> NotifyOption { NotifyOption::DoPersist });
-               self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger)
+               self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, self.chain_hash, &self.node_signer, &self.default_configuration, &self.logger)
                        .map(|(a, b)| (a, Vec::new(), b)));
 
                let last_best_block_height = self.best_block.read().unwrap().height();
                if height < last_best_block_height {
                        let timestamp = self.highest_seen_timestamp.load(Ordering::Acquire);
-                       self.do_chain_event(Some(last_best_block_height), |channel| channel.best_block_updated(last_best_block_height, timestamp as u32, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger));
+                       self.do_chain_event(Some(last_best_block_height), |channel| channel.best_block_updated(last_best_block_height, timestamp as u32, self.chain_hash, &self.node_signer, &self.default_configuration, &self.logger));
                }
        }
 
@@ -7519,7 +7521,7 @@ where
                                self, || -> NotifyOption { NotifyOption::DoPersist });
                *self.best_block.write().unwrap() = BestBlock::new(block_hash, height);
 
-               self.do_chain_event(Some(height), |channel| channel.best_block_updated(height, header.time, self.genesis_hash.clone(), &self.node_signer, &self.default_configuration, &self.logger));
+               self.do_chain_event(Some(height), |channel| channel.best_block_updated(height, header.time, self.chain_hash, &self.node_signer, &self.default_configuration, &self.logger));
 
                macro_rules! max_time {
                        ($timestamp: expr) => {
@@ -7639,7 +7641,7 @@ where
                                                                                msg: announcement_sigs,
                                                                        });
                                                                        if let Some(height) = height_opt {
-                                                                               if let Some(announcement) = channel.get_signed_channel_announcement(&self.node_signer, self.genesis_hash, height, &self.default_configuration) {
+                                                                               if let Some(announcement) = channel.get_signed_channel_announcement(&self.node_signer, self.chain_hash, height, &self.default_configuration) {
                                                                                        pending_msg_events.push(events::MessageSendEvent::BroadcastChannelAnnouncement {
                                                                                                msg: announcement,
                                                                                                // Note that announcement_signatures fails if the channel cannot be announced,
@@ -8249,7 +8251,7 @@ where
                                let mut peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
                                let peer_state = &mut *peer_state_lock;
                                if let Some(ChannelPhase::UnfundedOutboundV1(chan)) = peer_state.channel_by_id.get_mut(&msg.channel_id) {
-                                       if let Ok(msg) = chan.maybe_handle_error_without_close(self.genesis_hash, &self.fee_estimator) {
+                                       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,
                                                        msg,
@@ -8272,8 +8274,8 @@ where
                provided_init_features(&self.default_configuration)
        }
 
-       fn get_genesis_hashes(&self) -> Option<Vec<ChainHash>> {
-               Some(vec![ChainHash::from(&self.genesis_hash[..])])
+       fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
+               Some(vec![self.chain_hash])
        }
 
        fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) {
@@ -8818,7 +8820,7 @@ where
 
                write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
 
-               self.genesis_hash.write(writer)?;
+               self.chain_hash.write(writer)?;
                {
                        let best_block = self.best_block.read().unwrap();
                        best_block.height().write(writer)?;
@@ -9229,7 +9231,7 @@ where
        fn read<Reader: io::Read>(reader: &mut Reader, mut args: ChannelManagerReadArgs<'a, M, T, ES, NS, SP, F, R, L>) -> Result<Self, DecodeError> {
                let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
 
-               let genesis_hash: BlockHash = Readable::read(reader)?;
+               let chain_hash: ChainHash = Readable::read(reader)?;
                let best_block_height: u32 = Readable::read(reader)?;
                let best_block_hash: BlockHash = Readable::read(reader)?;
 
@@ -9877,7 +9879,7 @@ where
                                                let mut outbound_scid_alias;
                                                loop {
                                                        outbound_scid_alias = fake_scid::Namespace::OutboundAlias
-                                                               .get_fake_scid(best_block_height, &genesis_hash, fake_scid_rand_bytes.as_ref().unwrap(), &args.entropy_source);
+                                                               .get_fake_scid(best_block_height, &chain_hash, fake_scid_rand_bytes.as_ref().unwrap(), &args.entropy_source);
                                                        if outbound_scid_aliases.insert(outbound_scid_alias) { break; }
                                                }
                                                chan.context.set_outbound_scid_alias(outbound_scid_alias);
@@ -9991,7 +9993,7 @@ where
                }
 
                let channel_manager = ChannelManager {
-                       genesis_hash,
+                       chain_hash,
                        fee_estimator: bounded_fee_estimator,
                        chain_monitor: args.chain_monitor,
                        tx_broadcaster: args.tx_broadcaster,
@@ -10750,6 +10752,16 @@ mod tests {
                check_api_error_message(expected_message, res_err)
        }
 
+       fn check_channel_unavailable_error<T>(res_err: Result<T, APIError>, expected_channel_id: ChannelId, peer_node_id: PublicKey) {
+               let expected_message = format!("Channel with id {} not found for the passed counterparty node_id {}", expected_channel_id, peer_node_id);
+               check_api_error_message(expected_message, res_err)
+       }
+
+       fn check_api_misuse_error<T>(res_err: Result<T, APIError>) {
+               let expected_message = "No such channel awaiting to be accepted.".to_string();
+               check_api_error_message(expected_message, res_err)
+       }
+
        fn check_api_error_message<T>(expected_err_message: String, res_err: Result<T, APIError>) {
                match res_err {
                        Err(APIError::APIMisuseError { err }) => {
@@ -10794,6 +10806,36 @@ mod tests {
                check_unkown_peer_error(nodes[0].node.update_channel_config(&unkown_public_key, &[channel_id], &ChannelConfig::default()), unkown_public_key);
        }
 
+       #[test]
+       fn test_api_calls_with_unavailable_channel() {
+               // Tests that our API functions that expects a `counterparty_node_id` and a `channel_id`
+               // as input, behaves as expected if the `counterparty_node_id` is a known peer in the
+               // `ChannelManager::per_peer_state` map, but the peer state doesn't contain a channel with
+               // the given `channel_id`.
+               let chanmon_cfg = create_chanmon_cfgs(2);
+               let node_cfg = create_node_cfgs(2, &chanmon_cfg);
+               let node_chanmgr = create_node_chanmgrs(2, &node_cfg, &[None, None]);
+               let nodes = create_network(2, &node_cfg, &node_chanmgr);
+
+               let counterparty_node_id = nodes[1].node.get_our_node_id();
+
+               // Dummy values
+               let channel_id = ChannelId::from_bytes([4; 32]);
+
+               // Test the API functions.
+               check_api_misuse_error(nodes[0].node.accept_inbound_channel(&channel_id, &counterparty_node_id, 42));
+
+               check_channel_unavailable_error(nodes[0].node.close_channel(&channel_id, &counterparty_node_id), channel_id, counterparty_node_id);
+
+               check_channel_unavailable_error(nodes[0].node.force_close_broadcasting_latest_txn(&channel_id, &counterparty_node_id), channel_id, counterparty_node_id);
+
+               check_channel_unavailable_error(nodes[0].node.force_close_without_broadcasting_txn(&channel_id, &counterparty_node_id), channel_id, counterparty_node_id);
+
+               check_channel_unavailable_error(nodes[0].node.forward_intercepted_htlc(InterceptId([0; 32]), &channel_id, counterparty_node_id, 1_000_000), channel_id, counterparty_node_id);
+
+               check_channel_unavailable_error(nodes[0].node.update_channel_config(&counterparty_node_id, &[channel_id], &ChannelConfig::default()), channel_id, counterparty_node_id);
+       }
+
        #[test]
        fn test_connection_limiting() {
                // Test that we limit un-channel'd peers and un-funded channels properly.
@@ -11054,6 +11096,30 @@ mod tests {
                        sender_intended_amt_msat - extra_fee_msat, 42, None, true, Some(extra_fee_msat)).is_ok());
        }
 
+       #[test]
+       fn test_final_incorrect_cltv(){
+               let chanmon_cfg = create_chanmon_cfgs(1);
+               let node_cfg = create_node_cfgs(1, &chanmon_cfg);
+               let node_chanmgr = create_node_chanmgrs(1, &node_cfg, &[None]);
+               let node = create_network(1, &node_cfg, &node_chanmgr);
+
+               let result = node[0].node.construct_recv_pending_htlc_info(msgs::InboundOnionPayload::Receive {
+                       amt_msat: 100,
+                       outgoing_cltv_value: 22,
+                       payment_metadata: None,
+                       keysend_preimage: None,
+                       payment_data: Some(msgs::FinalOnionHopData {
+                               payment_secret: PaymentSecret([0; 32]), total_msat: 100,
+                       }),
+                       custom_tlvs: Vec::new(),
+               }, [0; 32], PaymentHash([0; 32]), 100, 23, None, true, None);
+
+               // Should not return an error as this condition:
+               // https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
+               // is not satisfied.
+               assert!(result.is_ok());
+       }
+
        #[test]
        fn test_inbound_anchors_manual_acceptance() {
                // Tests that we properly limit inbound channels when we have the manual-channel-acceptance
index 5e90ee7e92e31d0005dd65b35ac22c68a9eb9c98..c75ee379d8dae1e49b51d4ddf74b183e94172886 100644 (file)
@@ -40,7 +40,7 @@ use crate::util::config::{UserConfig, MaxDustHTLCExposure};
 use bitcoin::hash_types::BlockHash;
 use bitcoin::blockdata::script::{Builder, Script};
 use bitcoin::blockdata::opcodes;
-use bitcoin::blockdata::constants::genesis_block;
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::network::constants::Network;
 use bitcoin::{PackedLockTime, Sequence, Transaction, TxIn, TxOut, Witness};
 use bitcoin::OutPoint as BitcoinOutPoint;
@@ -5830,8 +5830,8 @@ fn bolt2_open_channel_sending_node_checks_part2() {
        assert!(node0_to_1_send_open_channel.to_self_delay==BREAKDOWN_TIMEOUT);
 
        // BOLT #2 spec: Sending node must ensure the chain_hash value identifies the chain it wishes to open the channel within.
-       let chain_hash=genesis_block(Network::Testnet).header.block_hash();
-       assert_eq!(node0_to_1_send_open_channel.chain_hash,chain_hash);
+       let chain_hash = ChainHash::using_genesis_block(Network::Testnet);
+       assert_eq!(node0_to_1_send_open_channel.chain_hash, chain_hash);
 
        // BOLT #2 spec: Sending node must set funding_pubkey, revocation_basepoint, htlc_basepoint, payment_basepoint, and delayed_payment_basepoint to valid DER-encoded, compressed, secp256k1 pubkeys.
        assert!(PublicKey::from_slice(&node0_to_1_send_open_channel.funding_pubkey.serialize()).is_ok());
index a68ac35218594689cd36402b7b4c05df3fa7321c..f86dc74befe255adc64caf31bdf8bff9cf91a697 100644 (file)
@@ -29,7 +29,7 @@ use bitcoin::secp256k1::PublicKey;
 use bitcoin::secp256k1::ecdsa::Signature;
 use bitcoin::{secp256k1, Witness};
 use bitcoin::blockdata::script::Script;
-use bitcoin::hash_types::{Txid, BlockHash};
+use bitcoin::hash_types::Txid;
 
 use crate::blinded_path::payment::ReceiveTlvs;
 use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
@@ -177,7 +177,7 @@ pub struct Pong {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct OpenChannel {
        /// The genesis hash of the blockchain where the channel is to be opened
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// A temporary channel ID, until the funding outpoint is announced
        pub temporary_channel_id: ChannelId,
        /// The channel value
@@ -231,7 +231,7 @@ pub struct OpenChannel {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct OpenChannelV2 {
        /// The genesis hash of the blockchain where the channel is to be opened
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint
        pub temporary_channel_id: ChannelId,
        /// The feerate for the funding transaction set by the channel initiator
@@ -1072,7 +1072,7 @@ pub struct UnsignedChannelAnnouncement {
        /// The advertised channel features
        pub features: ChannelFeatures,
        /// The genesis hash of the blockchain where the channel is to be opened
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The short channel ID
        pub short_channel_id: u64,
        /// One of the two `node_id`s which are endpoints of this channel
@@ -1112,7 +1112,7 @@ pub struct ChannelAnnouncement {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct UnsignedChannelUpdate {
        /// The genesis hash of the blockchain where the channel is to be opened
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The short channel ID
        pub short_channel_id: u64,
        /// A strictly monotonic announcement counter, with gaps allowed, specific to this channel
@@ -1164,7 +1164,7 @@ pub struct ChannelUpdate {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct QueryChannelRange {
        /// The genesis hash of the blockchain being queried
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The height of the first block for the channel UTXOs being queried
        pub first_blocknum: u32,
        /// The number of blocks to include in the query results
@@ -1185,7 +1185,7 @@ pub struct QueryChannelRange {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct ReplyChannelRange {
        /// The genesis hash of the blockchain being queried
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The height of the first block in the range of the reply
        pub first_blocknum: u32,
        /// The number of blocks included in the range of the reply
@@ -1210,7 +1210,7 @@ pub struct ReplyChannelRange {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct QueryShortChannelIds {
        /// The genesis hash of the blockchain being queried
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The short_channel_ids that are being queried
        pub short_channel_ids: Vec<u64>,
 }
@@ -1224,7 +1224,7 @@ pub struct QueryShortChannelIds {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct ReplyShortChannelIdsEnd {
        /// The genesis hash of the blockchain that was queried
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// Indicates if the query recipient maintains up-to-date channel
        /// information for the `chain_hash`
        pub full_information: bool,
@@ -1238,7 +1238,7 @@ pub struct ReplyShortChannelIdsEnd {
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct GossipTimestampFilter {
        /// The genesis hash of the blockchain for channel and node information
-       pub chain_hash: BlockHash,
+       pub chain_hash: ChainHash,
        /// The starting unix timestamp
        pub first_timestamp: u32,
        /// The range of information in seconds
@@ -1420,11 +1420,11 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
        /// Note that this method is called before [`Self::peer_connected`].
        fn provided_init_features(&self, their_node_id: &PublicKey) -> InitFeatures;
 
-       /// Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports.
+       /// 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_genesis_hashes(&self) -> Option<Vec<ChainHash>>;
+       fn get_chain_hashes(&self) -> Option<Vec<ChainHash>>;
 }
 
 /// A trait to describe an object which can receive routing messages.
@@ -2507,7 +2507,7 @@ impl_writeable!(NodeAnnouncement, {
 
 impl Readable for QueryShortChannelIds {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
-               let chain_hash: BlockHash = Readable::read(r)?;
+               let chain_hash: ChainHash = Readable::read(r)?;
 
                let encoding_len: u16 = Readable::read(r)?;
                let encoding_type: u8 = Readable::read(r)?;
@@ -2583,7 +2583,7 @@ impl_writeable_msg!(QueryChannelRange, {
 
 impl Readable for ReplyChannelRange {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
-               let chain_hash: BlockHash = Readable::read(r)?;
+               let chain_hash: ChainHash = Readable::read(r)?;
                let first_blocknum: u32 = Readable::read(r)?;
                let number_of_blocks: u32 = Readable::read(r)?;
                let sync_complete: bool = Readable::read(r)?;
@@ -2648,7 +2648,6 @@ impl_writeable_msg!(GossipTimestampFilter, {
 #[cfg(test)]
 mod tests {
        use std::convert::TryFrom;
-       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::{Transaction, PackedLockTime, TxIn, Script, Sequence, Witness, TxOut};
        use hex;
        use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -2663,9 +2662,10 @@ mod tests {
        use bitcoin::hashes::hex::FromHex;
        use bitcoin::util::address::Address;
        use bitcoin::network::constants::Network;
+       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
-       use bitcoin::hash_types::{Txid, BlockHash};
+       use bitcoin::hash_types::Txid;
 
        use bitcoin::secp256k1::{PublicKey,SecretKey};
        use bitcoin::secp256k1::{Secp256k1, Message};
@@ -2794,7 +2794,7 @@ mod tests {
                }
                let unsigned_channel_announcement = msgs::UnsignedChannelAnnouncement {
                        features,
-                       chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                        short_channel_id: 2316138423780173,
                        node_id_1: NodeId::from_pubkey(&pubkey_1),
                        node_id_2: NodeId::from_pubkey(&pubkey_2),
@@ -2816,7 +2816,7 @@ mod tests {
                } else {
                        target_value.append(&mut hex::decode("0000").unwrap());
                }
-               target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                target_value.append(&mut hex::decode("00083a840000034d031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
                if excess_data {
                        target_value.append(&mut hex::decode("0a00001400001e000028").unwrap());
@@ -2945,7 +2945,7 @@ mod tests {
                let (privkey_1, _) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
                let sig_1 = get_sig_on!(privkey_1, secp_ctx, String::from("01010101010101010101010101010101"));
                let unsigned_channel_update = msgs::UnsignedChannelUpdate {
-                       chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                        short_channel_id: 2316138423780173,
                        timestamp: 20190119,
                        flags: if direction { 1 } else { 0 } | if disable { 1 << 1 } else { 0 },
@@ -2962,7 +2962,7 @@ mod tests {
                };
                let encoded_value = channel_update.encode();
                let mut target_value = hex::decode("d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a").unwrap();
-               target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                target_value.append(&mut hex::decode("00083a840000034d013413a7").unwrap());
                target_value.append(&mut hex::decode("01").unwrap());
                target_value.append(&mut hex::decode("00").unwrap());
@@ -3003,7 +3003,7 @@ mod tests {
                let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
                let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
                let open_channel = msgs::OpenChannel {
-                       chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                        temporary_channel_id: ChannelId::from_bytes([2; 32]),
                        funding_satoshis: 1311768467284833366,
                        push_msat: 2536655962884945560,
@@ -3026,7 +3026,7 @@ mod tests {
                };
                let encoded_value = open_channel.encode();
                let mut target_value = Vec::new();
-               target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                target_value.append(&mut hex::decode("02020202020202020202020202020202020202020202020202020202020202021234567890123456233403289122369832144668701144767633030896203198784335490624111800083a840000034d000c89d4c0bcc0bc031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f703f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
                if random_bit {
                        target_value.append(&mut hex::decode("20").unwrap());
@@ -3064,7 +3064,7 @@ mod tests {
                let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
                let (_, pubkey_7) = get_keys_from!("0707070707070707070707070707070707070707070707070707070707070707", secp_ctx);
                let open_channelv2 = msgs::OpenChannelV2 {
-                       chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                        temporary_channel_id: ChannelId::from_bytes([2; 32]),
                        funding_feerate_sat_per_1000_weight: 821716,
                        commitment_feerate_sat_per_1000_weight: 821716,
@@ -3089,7 +3089,7 @@ mod tests {
                };
                let encoded_value = open_channelv2.encode();
                let mut target_value = Vec::new();
-               target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+               target_value.append(&mut hex::decode("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap());
                target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
                target_value.append(&mut hex::decode("000c89d4").unwrap());
                target_value.append(&mut hex::decode("000c89d4").unwrap());
@@ -3662,7 +3662,7 @@ mod tests {
 
        #[test]
        fn encoding_init() {
-               let mainnet_hash = ChainHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap();
+               let mainnet_hash = ChainHash::using_genesis_block(Network::Bitcoin);
                assert_eq!(msgs::Init {
                        features: InitFeatures::from_le_bytes(vec![0xFF, 0xFF, 0xFF]),
                        networks: Some(vec![mainnet_hash]),
@@ -3900,7 +3900,7 @@ mod tests {
 
                for (first_blocknum, number_of_blocks, expected) in tests.into_iter() {
                        let sut = msgs::QueryChannelRange {
-                               chain_hash: BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Regtest),
                                first_blocknum,
                                number_of_blocks,
                        };
@@ -3911,12 +3911,12 @@ mod tests {
        #[test]
        fn encoding_query_channel_range() {
                let mut query_channel_range = msgs::QueryChannelRange {
-                       chain_hash: BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Regtest),
                        first_blocknum: 100000,
                        number_of_blocks: 1500,
                };
                let encoded_value = query_channel_range.encode();
-               let target_value = hex::decode("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206000186a0000005dc").unwrap();
+               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000186a0000005dc").unwrap();
                assert_eq!(encoded_value, target_value);
 
                query_channel_range = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
@@ -3931,8 +3931,8 @@ mod tests {
        }
 
        fn do_encoding_reply_channel_range(encoding_type: u8) {
-               let mut target_value = hex::decode("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206000b8a06000005dc01").unwrap();
-               let expected_chain_hash = BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let mut target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000b8a06000005dc01").unwrap();
+               let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut reply_channel_range = msgs::ReplyChannelRange {
                        chain_hash: expected_chain_hash,
                        first_blocknum: 756230,
@@ -3968,8 +3968,8 @@ mod tests {
        }
 
        fn do_encoding_query_short_channel_ids(encoding_type: u8) {
-               let mut target_value = hex::decode("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206").unwrap();
-               let expected_chain_hash = BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let mut target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut query_short_channel_ids = msgs::QueryShortChannelIds {
                        chain_hash: expected_chain_hash,
                        short_channel_ids: vec![0x0000000000008e, 0x0000000000003c69, 0x000000000045a6c4],
@@ -3994,13 +3994,13 @@ mod tests {
 
        #[test]
        fn encoding_reply_short_channel_ids_end() {
-               let expected_chain_hash = BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut reply_short_channel_ids_end = msgs::ReplyShortChannelIdsEnd {
                        chain_hash: expected_chain_hash,
                        full_information: true,
                };
                let encoded_value = reply_short_channel_ids_end.encode();
-               let target_value = hex::decode("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e220601").unwrap();
+               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f01").unwrap();
                assert_eq!(encoded_value, target_value);
 
                reply_short_channel_ids_end = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
@@ -4010,14 +4010,14 @@ mod tests {
 
        #[test]
        fn encoding_gossip_timestamp_filter(){
-               let expected_chain_hash = BlockHash::from_hex("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f").unwrap();
+               let expected_chain_hash = ChainHash::using_genesis_block(Network::Regtest);
                let mut gossip_timestamp_filter = msgs::GossipTimestampFilter {
                        chain_hash: expected_chain_hash,
                        first_timestamp: 1590000000,
                        timestamp_range: 0xffff_ffff,
                };
                let encoded_value = gossip_timestamp_filter.encode();
-               let target_value = hex::decode("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22065ec57980ffffffff").unwrap();
+               let target_value = hex::decode("06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f5ec57980ffffffff").unwrap();
                assert_eq!(encoded_value, target_value);
 
                gossip_timestamp_filter = Readable::read(&mut Cursor::new(&target_value[..])).unwrap();
index ca7d33f50c032907cef80d3629fd943e813ba4a7..709e15bc22ec6ce489b01336d2032185bf2261d1 100644 (file)
@@ -29,8 +29,7 @@ use crate::util::test_utils;
 use crate::util::config::{UserConfig, ChannelConfig, MaxDustHTLCExposure};
 use crate::util::errors::APIError;
 
-use bitcoin::hash_types::BlockHash;
-
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::hashes::{Hash, HashEngine};
 use bitcoin::hashes::hmac::{Hmac, HmacEngine};
 use bitcoin::hashes::sha256::Hash as Sha256;
@@ -234,12 +233,13 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(
 
 impl msgs::ChannelUpdate {
        fn dummy(short_channel_id: u64) -> msgs::ChannelUpdate {
+               use bitcoin::hash_types::BlockHash;
                use bitcoin::secp256k1::ffi::Signature as FFISignature;
                use bitcoin::secp256k1::ecdsa::Signature;
                msgs::ChannelUpdate {
                        signature: Signature::from(unsafe { FFISignature::new() }),
                        contents: msgs::UnsignedChannelUpdate {
-                               chain_hash: BlockHash::hash(&vec![0u8][..]),
+                               chain_hash: ChainHash::from(BlockHash::hash(&vec![0u8][..]).as_ref()),
                                short_channel_id,
                                timestamp: 0,
                                flags: 0,
index b806b138a59092721d10b8e9289d9f0d28df23a0..d6d9f7aaca02f7fb3ae7296467a91fa6414dba29 100644 (file)
@@ -901,12 +901,10 @@ impl OutboundPayments {
                        RetryableSendFailure::RouteNotFound
                })?;
 
-               if let Some(route_route_params) = route.route_params.as_mut() {
-                       if route_route_params.final_value_msat != route_params.final_value_msat {
-                               debug_assert!(false,
-                                       "Routers are expected to return a route which includes the requested final_value_msat");
-                               route_route_params.final_value_msat = route_params.final_value_msat;
-                       }
+               if route.route_params.as_ref() != Some(&route_params) {
+                       debug_assert!(false,
+                               "Routers are expected to return a Route which includes the requested RouteParameters");
+                       route.route_params = Some(route_params.clone());
                }
 
                let onion_session_privs = self.add_new_pending_payment(payment_hash,
@@ -963,12 +961,10 @@ impl OutboundPayments {
                        }
                };
 
-               if let Some(route_route_params) = route.route_params.as_mut() {
-                       if route_route_params.final_value_msat != route_params.final_value_msat {
-                               debug_assert!(false,
-                                       "Routers are expected to return a route which includes the requested final_value_msat");
-                               route_route_params.final_value_msat = route_params.final_value_msat;
-                       }
+               if route.route_params.as_ref() != Some(&route_params) {
+                       debug_assert!(false,
+                               "Routers are expected to return a Route which includes the requested RouteParameters");
+                       route.route_params = Some(route_params.clone());
                }
 
                for path in route.paths.iter() {
@@ -1958,7 +1954,9 @@ mod tests {
                router.expect_find_route(route_params.clone(), Ok(route.clone()));
                let mut route_params_w_failed_scid = route_params.clone();
                route_params_w_failed_scid.payment_params.previously_failed_channels.push(failed_scid);
-               router.expect_find_route(route_params_w_failed_scid, Ok(route.clone()));
+               let mut route_w_failed_scid = route.clone();
+               route_w_failed_scid.route_params = Some(route_params_w_failed_scid.clone());
+               router.expect_find_route(route_params_w_failed_scid, Ok(route_w_failed_scid));
                router.expect_find_route(route_params.clone(), Ok(route.clone()));
                router.expect_find_route(route_params.clone(), Ok(route.clone()));
 
index 26ecbb0bd249d116cf8e54f440145c60d1796bbd..9f6f233861b57a01f5bb6b6fc3a8b2ff843a9b5a 100644 (file)
@@ -147,6 +147,7 @@ fn mpp_retry() {
        // Check the remaining max total routing fee for the second attempt is 50_000 - 1_000 msat fee
        // used by the first path
        route_params.max_total_routing_fee_msat = Some(max_total_routing_fee_msat - 1_000);
+       route.route_params = Some(route_params.clone());
        nodes[0].router.expect_find_route(route_params, Ok(route));
        nodes[0].node.process_pending_htlc_forwards();
        check_added_monitors!(nodes[0], 1);
@@ -253,12 +254,12 @@ fn mpp_retry_overpay() {
 
        route.paths.remove(0);
        route_params.final_value_msat -= first_path_value;
-       route.route_params.as_mut().map(|p| p.final_value_msat -= first_path_value);
        route_params.payment_params.previously_failed_channels.push(chan_4_update.contents.short_channel_id);
-
        // Check the remaining max total routing fee for the second attempt accounts only for 1_000 msat
        // base fee, but not for overpaid value of the first try.
        route_params.max_total_routing_fee_msat.as_mut().map(|m| *m -= 1000);
+
+       route.route_params = Some(route_params.clone());
        nodes[0].router.expect_find_route(route_params, Ok(route));
        nodes[0].node.process_pending_htlc_forwards();
 
@@ -1906,7 +1907,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
        // Check for unknown channel id error.
        let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &ChannelId::from_bytes([42; 32]), nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
        assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable  {
-               err: format!("Channel with id {} not found for the passed counterparty node_id {}.",
+               err: format!("Channel with id {} not found for the passed counterparty node_id {}",
                        log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) });
 
        if test == InterceptTest::Fail {
@@ -2738,7 +2739,7 @@ fn retry_multi_path_single_failed_payment() {
 
        let mut retry_params = RouteParameters::from_payment_params_and_value(pay_params, 100_000_000);
        retry_params.max_total_routing_fee_msat = None;
-       route.route_params.as_mut().unwrap().final_value_msat = 100_000_000;
+       route.route_params = Some(retry_params.clone());
        nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));
 
        {
@@ -2809,9 +2810,7 @@ fn immediate_retry_on_failure() {
                                maybe_announced_channel: true,
                        }], blinded_tail: None },
                ],
-               route_params: Some(RouteParameters::from_payment_params_and_value(
-                       PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV),
-                       100_000_001)),
+               route_params: Some(route_params.clone()),
        };
        nodes[0].router.expect_find_route(route_params.clone(), Ok(route.clone()));
        // On retry, split the payment across both channels.
@@ -2821,9 +2820,9 @@ fn immediate_retry_on_failure() {
        route.paths[1].hops[0].fee_msat = 50_000_001;
        let mut pay_params = route_params.payment_params.clone();
        pay_params.previously_failed_channels.push(chans[0].short_channel_id.unwrap());
-       nodes[0].router.expect_find_route(
-               RouteParameters::from_payment_params_and_value(pay_params, amt_msat),
-               Ok(route.clone()));
+       let retry_params = RouteParameters::from_payment_params_and_value(pay_params, amt_msat);
+       route.route_params = Some(retry_params.clone());
+       nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));
 
        nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
                PaymentId(payment_hash.0), route_params, Retry::Attempts(1)).unwrap();
@@ -2933,6 +2932,7 @@ fn no_extra_retries_on_back_to_back_fail() {
        route.paths[0].hops[1].fee_msat = amt_msat;
        let mut retry_params = RouteParameters::from_payment_params_and_value(second_payment_params, amt_msat);
        retry_params.max_total_routing_fee_msat = None;
+       route.route_params = Some(retry_params.clone());
        nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));
 
        nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
@@ -3137,7 +3137,7 @@ fn test_simple_partial_retry() {
        route.paths.remove(0);
        let mut retry_params = RouteParameters::from_payment_params_and_value(second_payment_params, amt_msat / 2);
        retry_params.max_total_routing_fee_msat = None;
-       route.route_params.as_mut().unwrap().final_value_msat = amt_msat / 2;
+       route.route_params = Some(retry_params.clone());
        nodes[0].router.expect_find_route(retry_params, Ok(route.clone()));
 
        nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
@@ -3316,7 +3316,7 @@ fn test_threaded_payment_retries() {
 
        // from here on out, the retry `RouteParameters` amount will be amt/1000
        route_params.final_value_msat /= 1000;
-       route.route_params.as_mut().unwrap().final_value_msat /= 1000;
+       route.route_params = Some(route_params.clone());
        route.paths.pop();
 
        let end_time = Instant::now() + Duration::from_secs(1);
@@ -3358,6 +3358,7 @@ fn test_threaded_payment_retries() {
                new_route_params.payment_params.previously_failed_channels = previously_failed_channels.clone();
                new_route_params.max_total_routing_fee_msat.as_mut().map(|m| *m -= 100_000);
                route.paths[0].hops[1].short_channel_id += 1;
+               route.route_params = Some(new_route_params.clone());
                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());
@@ -3720,7 +3721,7 @@ fn test_retry_custom_tlvs() {
        send_payment(&nodes[2], &vec!(&nodes[1])[..], 1_500_000);
 
        let amt_msat = 1_000_000;
-       let (route, payment_hash, payment_preimage, payment_secret) =
+       let (mut route, payment_hash, payment_preimage, payment_secret) =
                get_route_and_payment_hash!(nodes[0], nodes[2], amt_msat);
 
        // Initiate the payment
@@ -3772,6 +3773,7 @@ fn test_retry_custom_tlvs() {
 
        // Retry the payment and make sure it succeeds
        route_params.payment_params.previously_failed_channels.push(chan_2_update.contents.short_channel_id);
+       route.route_params = Some(route_params.clone());
        nodes[0].router.expect_find_route(route_params, Ok(route));
        nodes[0].node.process_pending_htlc_forwards();
        check_added_monitors!(nodes[0], 1);
index 92826244e09ee2b03f674e49c9e229e0a65a20ff..933e7ee6ba58ee67e46260d14164ab0d46588a10 100644 (file)
@@ -279,7 +279,7 @@ impl ChannelMessageHandler for ErroringMessageHandler {
                features
        }
 
-       fn get_genesis_hashes(&self) -> Option<Vec<ChainHash>> {
+       fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
                // We don't enforce any chains upon peer connection for `ErroringMessageHandler` and leave it up
                // to users of `ErroringMessageHandler` to make decisions on network compatiblility.
                // There's not really any way to pull in specific networks here, and hardcoding can cause breakages.
@@ -1367,7 +1367,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                peer.set_their_node_id(their_node_id);
                                                                insert_node_id!();
                                                                let features = self.init_features(&their_node_id);
-                                                               let networks = self.message_handler.chan_handler.get_genesis_hashes();
+                                                               let networks = self.message_handler.chan_handler.get_chain_hashes();
                                                                let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_socket_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1380,7 +1380,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                peer.set_their_node_id(their_node_id);
                                                                insert_node_id!();
                                                                let features = self.init_features(&their_node_id);
-                                                               let networks = self.message_handler.chan_handler.get_genesis_hashes();
+                                                               let networks = self.message_handler.chan_handler.get_chain_hashes();
                                                                let resp = msgs::Init { features, networks, remote_network_address: filter_addresses(peer.their_socket_address.clone()) };
                                                                self.enqueue_message(peer, &resp);
                                                                peer.awaiting_pong_timer_tick_intervals = 0;
@@ -1498,7 +1498,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                if let wire::Message::Init(msg) = message {
                        // Check if we have any compatible chains if the `networks` field is specified.
                        if let Some(networks) = &msg.networks {
-                               if let Some(our_chains) = self.message_handler.chan_handler.get_genesis_hashes() {
+                               if let Some(our_chains) = self.message_handler.chan_handler.get_chain_hashes() {
                                        let mut have_compatible_chains = false;
                                        'our_chains: for our_chain in our_chains.iter() {
                                                for their_chain in networks {
index eb25ee961e1dd7e0db3f17de8d1c4a7197be09fc..0ebb9bc7f6fb88ffe5f3a43ba118685fbe8b4ba2 100644 (file)
@@ -30,7 +30,7 @@ use core::default::Default;
 
 use crate::ln::functional_test_utils::*;
 
-use bitcoin::blockdata::constants::genesis_block;
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::network::constants::Network;
 
 #[test]
@@ -505,7 +505,7 @@ fn test_scid_alias_returned() {
 
        // Build the expected channel update
        let contents = msgs::UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: last_hop[0].inbound_scid_alias.unwrap(),
                timestamp: 21,
                flags: 1,
index ef776a44dc11c484526f7f5baeb64db06498710b..edb6226041d2e694b31842a7149cda25ed28ebe8 100644 (file)
@@ -9,6 +9,8 @@
 
 //! The [`NetworkGraph`] stores the network gossip and [`P2PGossipSync`] fetches it from peers
 
+use bitcoin::blockdata::constants::ChainHash;
+
 use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
 use bitcoin::secp256k1::{PublicKey, Verification};
 use bitcoin::secp256k1::Secp256k1;
@@ -17,10 +19,8 @@ use bitcoin::secp256k1;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
 use bitcoin::hashes::hex::FromHex;
-use bitcoin::hash_types::BlockHash;
 
 use bitcoin::network::constants::Network;
-use bitcoin::blockdata::constants::genesis_block;
 
 use crate::events::{MessageSendEvent, MessageSendEventsProvider};
 use crate::ln::ChannelId;
@@ -166,7 +166,7 @@ impl FromStr for NodeId {
 pub struct NetworkGraph<L: Deref> where L::Target: Logger {
        secp_ctx: Secp256k1<secp256k1::VerifyOnly>,
        last_rapid_gossip_sync_timestamp: Mutex<Option<u32>>,
-       genesis_hash: BlockHash,
+       chain_hash: ChainHash,
        logger: L,
        // Lock order: channels -> nodes
        channels: RwLock<IndexedMap<u64, ChannelInfo>>,
@@ -368,9 +368,9 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
                }
        }
 
-       /// Gets the genesis hash for this network graph.
-       pub fn get_genesis_hash(&self) -> BlockHash {
-               self.genesis_hash
+       /// Gets the chain hash for this network graph.
+       pub fn get_chain_hash(&self) -> ChainHash {
+               self.chain_hash
        }
 }
 
@@ -581,7 +581,7 @@ where U::Target: UtxoLookup, L::Target: Logger
                pending_events.push(MessageSendEvent::SendGossipTimestampFilter {
                        node_id: their_node_id.clone(),
                        msg: GossipTimestampFilter {
-                               chain_hash: self.network_graph.genesis_hash,
+                               chain_hash: self.network_graph.chain_hash,
                                first_timestamp: gossip_start_time as u32, // 2106 issue!
                                timestamp_range: u32::max_value(),
                        },
@@ -620,7 +620,7 @@ where U::Target: UtxoLookup, L::Target: Logger
                let exclusive_end_scid = scid_from_parts(cmp::min(msg.end_blocknum() as u64, MAX_SCID_BLOCK), 0, 0);
 
                // Per spec, we must reply to a query. Send an empty message when things are invalid.
-               if msg.chain_hash != self.network_graph.genesis_hash || inclusive_start_scid.is_err() || exclusive_end_scid.is_err() || msg.number_of_blocks == 0 {
+               if msg.chain_hash != self.network_graph.chain_hash || inclusive_start_scid.is_err() || exclusive_end_scid.is_err() || msg.number_of_blocks == 0 {
                        let mut pending_events = self.pending_events.lock().unwrap();
                        pending_events.push(MessageSendEvent::SendReplyChannelRange {
                                node_id: their_node_id.clone(),
@@ -1282,7 +1282,7 @@ impl<L: Deref> Writeable for NetworkGraph<L> where L::Target: Logger {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
 
-               self.genesis_hash.write(writer)?;
+               self.chain_hash.write(writer)?;
                let channels = self.channels.read().unwrap();
                (channels.len() as u64).write(writer)?;
                for (ref chan_id, ref chan_info) in channels.unordered_iter() {
@@ -1308,7 +1308,7 @@ impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
        fn read<R: io::Read>(reader: &mut R, logger: L) -> Result<NetworkGraph<L>, DecodeError> {
                let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
 
-               let genesis_hash: BlockHash = Readable::read(reader)?;
+               let chain_hash: ChainHash = Readable::read(reader)?;
                let channels_count: u64 = Readable::read(reader)?;
                let mut channels = IndexedMap::new();
                for _ in 0..channels_count {
@@ -1331,7 +1331,7 @@ impl<L: Deref> ReadableArgs<L> for NetworkGraph<L> where L::Target: Logger {
 
                Ok(NetworkGraph {
                        secp_ctx: Secp256k1::verification_only(),
-                       genesis_hash,
+                       chain_hash,
                        logger,
                        channels: RwLock::new(channels),
                        nodes: RwLock::new(nodes),
@@ -1367,7 +1367,7 @@ impl<L: Deref> PartialEq for NetworkGraph<L> where L::Target: Logger {
                let b = if ord { (&other.channels, &other.nodes) } else { (&self.channels, &self.nodes) };
                let (channels_a, channels_b) = (a.0.unsafe_well_ordered_double_lock_self(), b.0.unsafe_well_ordered_double_lock_self());
                let (nodes_a, nodes_b) = (a.1.unsafe_well_ordered_double_lock_self(), b.1.unsafe_well_ordered_double_lock_self());
-               self.genesis_hash.eq(&other.genesis_hash) && channels_a.eq(&channels_b) && nodes_a.eq(&nodes_b)
+               self.chain_hash.eq(&other.chain_hash) && channels_a.eq(&channels_b) && nodes_a.eq(&nodes_b)
        }
 }
 
@@ -1376,7 +1376,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
        pub fn new(network: Network, logger: L) -> NetworkGraph<L> {
                Self {
                        secp_ctx: Secp256k1::verification_only(),
-                       genesis_hash: genesis_block(network).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(network),
                        logger,
                        channels: RwLock::new(IndexedMap::new()),
                        nodes: RwLock::new(IndexedMap::new()),
@@ -1608,7 +1608,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
                        return Err(LightningError{err: "Channel announcement node had a channel with itself".to_owned(), action: ErrorAction::IgnoreError});
                }
 
-               if msg.chain_hash != self.genesis_hash {
+               if msg.chain_hash != self.chain_hash {
                        return Err(LightningError {
                                err: "Channel announcement chain hash does not match genesis hash".to_owned(),
                                action: ErrorAction::IgnoreAndLog(Level::Debug),
@@ -1868,7 +1868,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
        fn update_channel_intern(&self, msg: &msgs::UnsignedChannelUpdate, full_msg: Option<&msgs::ChannelUpdate>, sig: Option<&secp256k1::ecdsa::Signature>) -> Result<(), LightningError> {
                let chan_enabled = msg.flags & (1 << 1) != (1 << 1);
 
-               if msg.chain_hash != self.genesis_hash {
+               if msg.chain_hash != self.chain_hash {
                        return Err(LightningError {
                                err: "Channel update chain hash does not match genesis hash".to_owned(),
                                action: ErrorAction::IgnoreAndLog(Level::Debug),
@@ -2068,7 +2068,7 @@ pub(crate) mod tests {
        use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::hashes::Hash;
        use bitcoin::network::constants::Network;
-       use bitcoin::blockdata::constants::genesis_block;
+       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::blockdata::script::Script;
        use bitcoin::blockdata::transaction::TxOut;
 
@@ -2140,7 +2140,7 @@ pub(crate) mod tests {
 
                let mut unsigned_announcement = UnsignedChannelAnnouncement {
                        features: channelmanager::provided_channel_features(&UserConfig::default()),
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 0,
                        node_id_1: NodeId::from_pubkey(&node_id_1),
                        node_id_2: NodeId::from_pubkey(&node_id_2),
@@ -2168,7 +2168,7 @@ pub(crate) mod tests {
 
        pub(crate) fn get_signed_channel_update<F: Fn(&mut UnsignedChannelUpdate)>(f: F, node_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> ChannelUpdate {
                let mut unsigned_channel_update = UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 0,
                        timestamp: 100,
                        flags: 0,
@@ -2373,7 +2373,7 @@ pub(crate) mod tests {
                // Test that channel announcements with the wrong chain hash are ignored (network graph is testnet,
                // announcement is mainnet).
                let incorrect_chain_announcement = get_signed_channel_announcement(|unsigned_announcement| {
-                       unsigned_announcement.chain_hash = genesis_block(Network::Bitcoin).header.block_hash();
+                       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) {
                        Ok(_) => panic!(),
@@ -2487,7 +2487,7 @@ pub(crate) mod tests {
                // Test that channel updates with the wrong chain hash are ignored (network graph is testnet, channel
                // update is mainet).
                let incorrect_chain_update = get_signed_channel_update(|unsigned_channel_update| {
-                       unsigned_channel_update.chain_hash = genesis_block(Network::Bitcoin).header.block_hash();
+                       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) {
@@ -2925,7 +2925,7 @@ pub(crate) mod tests {
                let node_privkey_1 = &SecretKey::from_slice(&[42; 32]).unwrap();
                let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_privkey_1);
 
-               let chain_hash = genesis_block(Network::Testnet).header.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(Network::Testnet);
 
                // It should ignore if gossip_queries feature is not enabled
                {
@@ -2962,7 +2962,7 @@ pub(crate) mod tests {
                let network_graph = create_network_graph();
                let (secp_ctx, gossip_sync) = create_gossip_sync(&network_graph);
 
-               let chain_hash = genesis_block(Network::Testnet).header.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(Network::Testnet);
                let node_1_privkey = &SecretKey::from_slice(&[42; 32]).unwrap();
                let node_2_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
                let node_id_2 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
@@ -3014,13 +3014,13 @@ pub(crate) mod tests {
                        &gossip_sync,
                        &node_id_2,
                        QueryChannelRange {
-                               chain_hash: genesis_block(Network::Bitcoin).header.block_hash(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                                first_blocknum: 0,
                                number_of_blocks: 0xffff_ffff,
                        },
                        false,
                        vec![ReplyChannelRange {
-                               chain_hash: genesis_block(Network::Bitcoin).header.block_hash(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Bitcoin),
                                first_blocknum: 0,
                                number_of_blocks: 0xffff_ffff,
                                sync_complete: true,
@@ -3255,7 +3255,7 @@ pub(crate) mod tests {
                let node_privkey = &SecretKey::from_slice(&[41; 32]).unwrap();
                let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
 
-               let chain_hash = genesis_block(Network::Testnet).header.block_hash();
+               let chain_hash = ChainHash::using_genesis_block(Network::Testnet);
 
                let result = gossip_sync.handle_query_short_channel_ids(&node_id, QueryShortChannelIds {
                        chain_hash,
index 28d452c56b616afde8e1aea886e5a0bfe65f8eb0..4c8a31bd73533fdf3ca4d19b869c8339edcc2167 100644 (file)
@@ -2830,7 +2830,7 @@ mod tests {
 
        use bitcoin::hashes::Hash;
        use bitcoin::network::constants::Network;
-       use bitcoin::blockdata::constants::genesis_block;
+       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::blockdata::script::Builder;
        use bitcoin::blockdata::opcodes;
        use bitcoin::blockdata::transaction::TxOut;
@@ -2961,7 +2961,7 @@ mod tests {
 
                // Disable other paths
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -2973,7 +2973,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -2985,7 +2985,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -2997,7 +2997,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3009,7 +3009,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3024,7 +3024,7 @@ mod tests {
                // Check against amount_to_transfer_over_msat.
                // Set minimal HTLC of 200_000_000 msat.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 3,
                        flags: 0,
@@ -3039,7 +3039,7 @@ mod tests {
                // Second hop only allows to forward 199_999_999 at most, thus not allowing the first hop to
                // be used.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 3,
                        flags: 0,
@@ -3062,7 +3062,7 @@ mod tests {
 
                // Lift the restriction on the first hop.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 4,
                        flags: 0,
@@ -3094,7 +3094,7 @@ mod tests {
                // One path allows transferring 35-40 sats, another one also allows 35-40 sats.
                // Thus, they can't send 60 without overpaying.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -3106,7 +3106,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 3,
                        flags: 0,
@@ -3120,7 +3120,7 @@ mod tests {
 
                // Make 0 fee.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -3132,7 +3132,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -3146,7 +3146,7 @@ mod tests {
 
                // Disable other paths
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 3,
                        flags: 2, // to disable
@@ -3171,7 +3171,7 @@ mod tests {
                // Now, test that if there are 2 paths, a "cheaper" by fee path wouldn't be prioritized
                // while taking even more fee to match htlc_minimum_msat.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 4,
                        flags: 0,
@@ -3183,7 +3183,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 3,
                        flags: 0,
@@ -3195,7 +3195,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 4,
                        flags: 0,
@@ -3240,7 +3240,7 @@ mod tests {
 
                // First disable all paths except the us -> node1 -> node2 path
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 3,
@@ -3254,7 +3254,7 @@ mod tests {
 
                // Set channel 4 to free but with a high htlc_minimum_msat
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -3298,7 +3298,7 @@ mod tests {
 
                // // Disable channels 4 and 12 by flags=2
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3310,7 +3310,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3742,7 +3742,7 @@ mod tests {
 
                // Disabling channels 6 & 7 by flags=2
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3754,7 +3754,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3816,7 +3816,7 @@ mod tests {
 
                // Disabling channels 6 & 7 by flags=2
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -3828,7 +3828,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2, // to disable
@@ -4177,7 +4177,7 @@ mod tests {
 
                // First disable all other paths.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 2,
@@ -4189,7 +4189,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 2,
@@ -4204,7 +4204,7 @@ mod tests {
                // Make the first channel (#1) very permissive,
                // and we will be testing all limits on the second channel.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -4219,7 +4219,7 @@ mod tests {
                // First, let's see if routing works if we have absolutely no idea about the available amount.
                // In this case, it should be set to 250_000 sats.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -4258,7 +4258,7 @@ mod tests {
                // Check that setting next_outbound_htlc_limit_msat in first_hops limits the channels.
                // Disable channel #1 and use another first hop.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 3,
                        flags: 2,
@@ -4301,7 +4301,7 @@ mod tests {
 
                // Enable channel #1 back.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 4,
                        flags: 0,
@@ -4316,7 +4316,7 @@ mod tests {
 
                // Now let's see if routing works if we know only htlc_maximum_msat.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 3,
                        flags: 0,
@@ -4357,7 +4357,7 @@ mod tests {
                // We can't change UTXO capacity on the fly, so we'll disable
                // the existing channel and add another one with the capacity we need.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 4,
                        flags: 2,
@@ -4381,7 +4381,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 333);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 333,
                        timestamp: 1,
                        flags: 0,
@@ -4393,7 +4393,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 333,
                        timestamp: 1,
                        flags: 1,
@@ -4431,7 +4431,7 @@ mod tests {
 
                // Now let's see if routing chooses htlc_maximum_msat over UTXO capacity.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 333,
                        timestamp: 6,
                        flags: 0,
@@ -4486,7 +4486,7 @@ mod tests {
 
                // Disable other potential paths.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 2,
@@ -4498,7 +4498,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2,
@@ -4513,7 +4513,7 @@ mod tests {
                // Limit capacities
 
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -4525,7 +4525,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -4538,7 +4538,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 0,
@@ -4550,7 +4550,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 11,
                        timestamp: 2,
                        flags: 0,
@@ -4616,7 +4616,7 @@ mod tests {
 
                // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50).
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -4628,7 +4628,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -4729,7 +4729,7 @@ mod tests {
 
                // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50).
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -4741,7 +4741,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -4756,7 +4756,7 @@ mod tests {
                // Path via node7 is channels {12, 13}. Limit them to 60 and 60 sats
                // (total limit 60).
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -4768,7 +4768,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -4783,7 +4783,7 @@ mod tests {
                // Path via node1 is channels {2, 4}. Limit them to 200 and 180 sats
                // (total capacity 180 sats).
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -4795,7 +4795,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -4916,7 +4916,7 @@ mod tests {
 
                // Disable other potential paths.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 2,
@@ -4928,7 +4928,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2,
@@ -4942,7 +4942,7 @@ mod tests {
 
                // Path via {node0, node2} is channels {1, 3, 5}.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -4954,7 +4954,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -4969,7 +4969,7 @@ mod tests {
                // Capacity of 200 sats because this channel will be used by 3rd path as well.
                add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 5,
                        timestamp: 2,
                        flags: 0,
@@ -4985,7 +4985,7 @@ mod tests {
                // Add 100 sats to the capacities of {12, 13}, because these channels
                // are also used for 3rd path. 100 sats for the rest. Total capacity: 100 sats.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -4997,7 +4997,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -5010,7 +5010,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 0,
@@ -5022,7 +5022,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 11,
                        timestamp: 2,
                        flags: 0,
@@ -5091,7 +5091,7 @@ mod tests {
 
                // Disable other potential paths.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 2,
@@ -5103,7 +5103,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2,
@@ -5117,7 +5117,7 @@ mod tests {
 
                // Path via {node0, node2} is channels {1, 3, 5}.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -5129,7 +5129,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -5144,7 +5144,7 @@ mod tests {
                // Capacity of 200 sats because this channel will be used by 3rd path as well.
                add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 5,
                        timestamp: 2,
                        flags: 0,
@@ -5160,7 +5160,7 @@ mod tests {
                // Add 100 sats to the capacities of {12, 13}, because these channels
                // are also used for 3rd path. 100 sats for the rest. Total capacity: 100 sats.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -5172,7 +5172,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -5185,7 +5185,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 0,
@@ -5197,7 +5197,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 11,
                        timestamp: 2,
                        flags: 0,
@@ -5262,7 +5262,7 @@ mod tests {
 
                // Disable other potential paths.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 2,
@@ -5275,7 +5275,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 7,
                        timestamp: 2,
                        flags: 2,
@@ -5289,7 +5289,7 @@ mod tests {
 
                // Path via {node0, node2} is channels {1, 3, 5}.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -5301,7 +5301,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -5315,7 +5315,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 5,
                        timestamp: 2,
                        flags: 0,
@@ -5338,7 +5338,7 @@ mod tests {
                // - fee for channel 6 is 150 sats
                // Let's test this by enforcing these 2 conditions and removing other limits.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -5350,7 +5350,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -5363,7 +5363,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 2,
                        flags: 0,
@@ -5375,7 +5375,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 11,
                        timestamp: 2,
                        flags: 0,
@@ -5464,7 +5464,7 @@ mod tests {
                // we think we can only send up to 1 additional sat over the last-hop but refuse to as its
                // under 5% of our payment amount.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -5476,7 +5476,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -5488,7 +5488,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -5500,7 +5500,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0|2, // Channel disabled
@@ -5557,7 +5557,7 @@ mod tests {
 
                // Path via node0 is channels {1, 3}. Limit them to 100 and 50 sats (total limit 50);
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 2,
                        flags: 0,
@@ -5569,7 +5569,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 2,
                        flags: 0,
@@ -5583,7 +5583,7 @@ mod tests {
 
                // Path via node7 is channels {12, 13}. Limit them to 60 and 60 sats (total limit 60);
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -5595,7 +5595,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -5609,7 +5609,7 @@ mod tests {
 
                // Path via node1 is channels {2, 4}. Limit them to 20 and 20 sats (total capacity 20 sats).
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -5621,7 +5621,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -5716,7 +5716,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 1,
                        flags: 0,
@@ -5731,7 +5731,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(5)), 5);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 5,
                        timestamp: 1,
                        flags: 0,
@@ -5746,7 +5746,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 1,
                        flags: 0,
@@ -5761,7 +5761,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[3], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 3,
                        timestamp: 1,
                        flags: 0,
@@ -5776,7 +5776,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 1,
                        flags: 0,
@@ -5790,7 +5790,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[6], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 1,
                        flags: 0,
@@ -5851,7 +5851,7 @@ mod tests {
                // We modify the graph to set the htlc_maximum of channel 2 to below the value we wish to
                // send.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -5864,7 +5864,7 @@ mod tests {
                });
 
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 12,
                        timestamp: 2,
                        flags: 0,
@@ -5921,7 +5921,7 @@ mod tests {
                // gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We
                // then try to send 90_000.
                update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 2,
                        timestamp: 2,
                        flags: 0,
@@ -5933,7 +5933,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -6473,7 +6473,7 @@ mod tests {
                // Set the fee on channel 13 to 100% to match channel 4 giving us two equivalent paths (us
                // -> node 7 -> node2 and us -> node 1 -> node 2) which we should balance over.
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 4,
                        timestamp: 2,
                        flags: 0,
@@ -6485,7 +6485,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 13,
                        timestamp: 2,
                        flags: 0,
@@ -7151,7 +7151,7 @@ mod tests {
                add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[1],
                        ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 1,
                        flags: 0,
@@ -7163,7 +7163,7 @@ mod tests {
                        excess_data: Vec::new()
                });
                update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 1,
                        timestamp: 1,
                        flags: 1,
@@ -7584,7 +7584,7 @@ mod tests {
 
                add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[6], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
                update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-                       chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                        short_channel_id: 6,
                        timestamp: 1,
                        flags: 0,
@@ -7691,6 +7691,203 @@ mod tests {
                assert_eq!(route.paths.len(), 1);
                assert_eq!(route.get_total_amount(), amt_msat);
        }
+
+       #[test]
+       fn first_hop_preferred_over_hint() {
+               // Check that if we have a first hop to a peer we'd always prefer that over a route hint
+               // they gave us, but we'd still consider all subsequent hints if they are more attractive.
+               let secp_ctx = Secp256k1::new();
+               let logger = Arc::new(ln_test_utils::TestLogger::new());
+               let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
+               let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
+               let scorer = ln_test_utils::TestScorer::new();
+               let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+               let random_seed_bytes = keys_manager.get_secure_random_bytes();
+               let config = UserConfig::default();
+
+               let amt_msat = 1_000_000;
+               let (our_privkey, our_node_id, privkeys, nodes) = get_nodes(&secp_ctx);
+
+               add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0],
+                       ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
+               update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
+                       short_channel_id: 1,
+                       timestamp: 1,
+                       flags: 0,
+                       cltv_expiry_delta: 42,
+                       htlc_minimum_msat: 1_000,
+                       htlc_maximum_msat: 10_000_000,
+                       fee_base_msat: 800,
+                       fee_proportional_millionths: 0,
+                       excess_data: Vec::new()
+               });
+               update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
+                       short_channel_id: 1,
+                       timestamp: 1,
+                       flags: 1,
+                       cltv_expiry_delta: 42,
+                       htlc_minimum_msat: 1_000,
+                       htlc_maximum_msat: 10_000_000,
+                       fee_base_msat: 800,
+                       fee_proportional_millionths: 0,
+                       excess_data: Vec::new()
+               });
+
+               add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[1],
+                       ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 2);
+               update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
+                       short_channel_id: 2,
+                       timestamp: 2,
+                       flags: 0,
+                       cltv_expiry_delta: 42,
+                       htlc_minimum_msat: 1_000,
+                       htlc_maximum_msat: 10_000_000,
+                       fee_base_msat: 800,
+                       fee_proportional_millionths: 0,
+                       excess_data: Vec::new()
+               });
+               update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
+                       chain_hash: ChainHash::using_genesis_block(Network::Testnet),
+                       short_channel_id: 2,
+                       timestamp: 2,
+                       flags: 1,
+                       cltv_expiry_delta: 42,
+                       htlc_minimum_msat: 1_000,
+                       htlc_maximum_msat: 10_000_000,
+                       fee_base_msat: 800,
+                       fee_proportional_millionths: 0,
+                       excess_data: Vec::new()
+               });
+
+               let dest_node_id = nodes[2];
+
+               let route_hint = RouteHint(vec![RouteHintHop {
+                       src_node_id: our_node_id,
+                       short_channel_id: 44,
+                       fees: RoutingFees {
+                               base_msat: 234,
+                               proportional_millionths: 0,
+                       },
+                       cltv_expiry_delta: 10,
+                       htlc_minimum_msat: None,
+                       htlc_maximum_msat: Some(5_000_000),
+               },
+               RouteHintHop {
+                       src_node_id: nodes[0],
+                       short_channel_id: 45,
+                       fees: RoutingFees {
+                               base_msat: 123,
+                               proportional_millionths: 0,
+                       },
+                       cltv_expiry_delta: 10,
+                       htlc_minimum_msat: None,
+                       htlc_maximum_msat: None,
+               }]);
+
+               let payment_params = PaymentParameters::from_node_id(dest_node_id, 42)
+                       .with_route_hints(vec![route_hint]).unwrap()
+                       .with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
+               let route_params = RouteParameters::from_payment_params_and_value(
+                       payment_params, amt_msat);
+
+               // First create an insufficient first hop for channel with SCID 1 and check we'd use the
+               // route hint.
+               let first_hop = get_channel_details(Some(1), nodes[0],
+                       channelmanager::provided_init_features(&config), 999_999);
+               let first_hops = vec![first_hop];
+
+               let route = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
+                       Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
+                       &Default::default(), &random_seed_bytes).unwrap();
+               assert_eq!(route.paths.len(), 1);
+               assert_eq!(route.get_total_amount(), amt_msat);
+               assert_eq!(route.paths[0].hops.len(), 2);
+               assert_eq!(route.paths[0].hops[0].short_channel_id, 44);
+               assert_eq!(route.paths[0].hops[1].short_channel_id, 45);
+               assert_eq!(route.get_total_fees(), 123);
+
+               // Now check we would trust our first hop info, i.e., fail if we detect the route hint is
+               // for a first hop channel.
+               let mut first_hop = get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 999_999);
+               first_hop.outbound_scid_alias = Some(44);
+               let first_hops = vec![first_hop];
+
+               let route_res = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
+                       Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
+                       &Default::default(), &random_seed_bytes);
+               assert!(route_res.is_err());
+
+               // Finally check we'd use the first hop if has sufficient outbound capacity. But we'd stil
+               // use the cheaper second hop of the route hint.
+               let mut first_hop = get_channel_details(Some(1), nodes[0],
+                       channelmanager::provided_init_features(&config), 10_000_000);
+               first_hop.outbound_scid_alias = Some(44);
+               let first_hops = vec![first_hop];
+
+               let route = get_route(&our_node_id, &route_params.clone(), &network_graph.read_only(),
+                       Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
+                       &Default::default(), &random_seed_bytes).unwrap();
+               assert_eq!(route.paths.len(), 1);
+               assert_eq!(route.get_total_amount(), amt_msat);
+               assert_eq!(route.paths[0].hops.len(), 2);
+               assert_eq!(route.paths[0].hops[0].short_channel_id, 1);
+               assert_eq!(route.paths[0].hops[1].short_channel_id, 45);
+               assert_eq!(route.get_total_fees(), 123);
+       }
+
+       #[test]
+       fn allow_us_being_first_hint() {
+               // Check that we consider a route hint even if we are the src of the first hop.
+               let secp_ctx = Secp256k1::new();
+               let logger = Arc::new(ln_test_utils::TestLogger::new());
+               let network_graph = Arc::new(NetworkGraph::new(Network::Testnet, Arc::clone(&logger)));
+               let scorer = ln_test_utils::TestScorer::new();
+               let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+               let random_seed_bytes = keys_manager.get_secure_random_bytes();
+               let config = UserConfig::default();
+
+               let (_, our_node_id, _, nodes) = get_nodes(&secp_ctx);
+
+               let amt_msat = 1_000_000;
+               let dest_node_id = nodes[1];
+
+               let first_hop = get_channel_details(Some(1), nodes[0], channelmanager::provided_init_features(&config), 10_000_000);
+               let first_hops = vec![first_hop];
+
+               let route_hint = RouteHint(vec![RouteHintHop {
+                       src_node_id: our_node_id,
+                       short_channel_id: 44,
+                       fees: RoutingFees {
+                               base_msat: 123,
+                               proportional_millionths: 0,
+                       },
+                       cltv_expiry_delta: 10,
+                       htlc_minimum_msat: None,
+                       htlc_maximum_msat: None,
+               }]);
+
+               let payment_params = PaymentParameters::from_node_id(dest_node_id, 42)
+                       .with_route_hints(vec![route_hint]).unwrap()
+                       .with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
+
+               let route_params = RouteParameters::from_payment_params_and_value(
+                       payment_params, amt_msat);
+
+
+               let route = get_route(&our_node_id, &route_params, &network_graph.read_only(),
+                       Some(&first_hops.iter().collect::<Vec<_>>()), Arc::clone(&logger), &scorer,
+                       &Default::default(), &random_seed_bytes).unwrap();
+
+               assert_eq!(route.paths.len(), 1);
+               assert_eq!(route.get_total_amount(), amt_msat);
+               assert_eq!(route.get_total_fees(), 0);
+               assert_eq!(route.paths[0].hops.len(), 1);
+
+               assert_eq!(route.paths[0].hops[0].short_channel_id, 44);
+       }
 }
 
 #[cfg(all(any(test, ldk_bench), not(feature = "no-std")))]
index 207e1d69bd98d2b66974884ab1226f1b36562a73..9c907c3f7fe4bd38d7526b9d10871769ea537d27 100644 (file)
@@ -2179,7 +2179,7 @@ mod tests {
        use crate::util::ser::{ReadableArgs, Writeable};
        use crate::util::test_utils::{self, TestLogger};
 
-       use bitcoin::blockdata::constants::genesis_block;
+       use bitcoin::blockdata::constants::ChainHash;
        use bitcoin::hashes::Hash;
        use bitcoin::hashes::sha256d::Hash as Sha256dHash;
        use bitcoin::network::constants::Network;
@@ -2256,7 +2256,7 @@ mod tests {
                network_graph: &mut NetworkGraph<&TestLogger>, short_channel_id: u64, node_1_key: SecretKey,
                node_2_key: SecretKey
        ) {
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
+               let genesis_hash = ChainHash::using_genesis_block(Network::Testnet);
                let node_1_secret = &SecretKey::from_slice(&[39; 32]).unwrap();
                let node_2_secret = &SecretKey::from_slice(&[40; 32]).unwrap();
                let secp_ctx = Secp256k1::new();
@@ -2289,7 +2289,7 @@ mod tests {
                network_graph: &mut NetworkGraph<&TestLogger>, short_channel_id: u64, node_key: SecretKey,
                flags: u8, htlc_maximum_msat: u64, timestamp: u32,
        ) {
-               let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
+               let genesis_hash = ChainHash::using_genesis_block(Network::Testnet);
                let secp_ctx = Secp256k1::new();
                let unsigned_update = UnsignedChannelUpdate {
                        chain_hash: genesis_hash,
index d0e44eb214cf4fe3d43a5a8c52b6b6e340a9f2b9..f4048f58d4dc9ef5478b43b9922c8082754938c4 100644 (file)
@@ -14,10 +14,10 @@ use crate::ln::msgs::{UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingM
 use crate::util::test_utils;
 use crate::util::ser::Writeable;
 
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hashes::Hash;
 use bitcoin::network::constants::Network;
-use bitcoin::blockdata::constants::genesis_block;
 
 use hex;
 
@@ -39,7 +39,7 @@ pub(super) fn add_channel(
 
        let unsigned_announcement = UnsignedChannelAnnouncement {
                features,
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id,
                node_id_1,
                node_id_2,
@@ -154,7 +154,7 @@ pub(super) fn build_line_graph() -> (
                        add_channel(&gossip_sync, &secp_ctx, &cur_privkey, &next_privkey,
                                ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), cur_short_channel_id);
                        update_channel(&gossip_sync, &secp_ctx, &cur_privkey, UnsignedChannelUpdate {
-                               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                                short_channel_id: cur_short_channel_id,
                                timestamp: idx as u32,
                                flags: 0,
@@ -166,7 +166,7 @@ pub(super) fn build_line_graph() -> (
                                excess_data: Vec::new()
                        });
                        update_channel(&gossip_sync, &secp_ctx, &next_privkey, UnsignedChannelUpdate {
-                               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                                short_channel_id: cur_short_channel_id,
                                timestamp: (idx as u32)+1,
                                flags: 1,
@@ -259,7 +259,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 1,
                timestamp: 1,
                flags: 1,
@@ -275,7 +275,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
        update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 2,
                timestamp: 1,
                flags: 0,
@@ -287,7 +287,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 2,
                timestamp: 1,
                flags: 1,
@@ -303,7 +303,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12);
        update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 12,
                timestamp: 1,
                flags: 0,
@@ -315,7 +315,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 12,
                timestamp: 1,
                flags: 1,
@@ -331,7 +331,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 3,
                timestamp: 1,
                flags: 0,
@@ -343,7 +343,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 3,
                timestamp: 1,
                flags: 1,
@@ -357,7 +357,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 4,
                timestamp: 1,
                flags: 0,
@@ -369,7 +369,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 4,
                timestamp: 1,
                flags: 1,
@@ -383,7 +383,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 13,
                timestamp: 1,
                flags: 0,
@@ -395,7 +395,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 13,
                timestamp: 1,
                flags: 1,
@@ -411,7 +411,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 6,
                timestamp: 1,
                flags: 0,
@@ -423,7 +423,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 6,
                timestamp: 1,
                flags: 1,
@@ -437,7 +437,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 11,
                timestamp: 1,
                flags: 0,
@@ -449,7 +449,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 11,
                timestamp: 1,
                flags: 1,
@@ -467,7 +467,7 @@ pub(super) fn build_graph() -> (
 
        add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7);
        update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 7,
                timestamp: 1,
                flags: 0,
@@ -479,7 +479,7 @@ pub(super) fn build_graph() -> (
                excess_data: Vec::new()
        });
        update_channel(&gossip_sync, &secp_ctx, &privkeys[5], UnsignedChannelUpdate {
-               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                short_channel_id: 7,
                timestamp: 1,
                flags: 1,
index 8733def13d95d26dc3d9c446cb5851d39c3b2ca3..164974672380b1272ffe23cc0bbb2d6ea26347c9 100644 (file)
@@ -13,7 +13,8 @@
 //! channel matches a UTXO on-chain, requiring at least some marginal on-chain transacting in
 //! order to announce a channel. This module handles that checking.
 
-use bitcoin::{BlockHash, TxOut};
+use bitcoin::TxOut;
+use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::hashes::hex::ToHex;
 
 use crate::events::MessageSendEvent;
@@ -60,11 +61,11 @@ pub enum UtxoResult {
 /// The `UtxoLookup` trait defines behavior for accessing on-chain UTXOs.
 pub trait UtxoLookup {
        /// Returns the transaction output of a funding transaction encoded by [`short_channel_id`].
-       /// Returns an error if `genesis_hash` is for a different chain or if such a transaction output
-       /// is unknown.
+       /// Returns an error if `chain_hash` is for a different chain or if such a transaction output is
+       /// unknown.
        ///
        /// [`short_channel_id`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#definition-of-short_channel_id
-       fn get_utxo(&self, genesis_hash: &BlockHash, short_channel_id: u64) -> UtxoResult;
+       fn get_utxo(&self, chain_hash: &ChainHash, short_channel_id: u64) -> UtxoResult;
 }
 
 enum ChannelAnnouncement {
@@ -127,7 +128,7 @@ pub struct UtxoFuture {
 /// once we have a concrete resolution of a request.
 pub(crate) struct UtxoResolver(Result<TxOut, UtxoLookupError>);
 impl UtxoLookup for UtxoResolver {
-       fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
+       fn get_utxo(&self, _chain_hash: &ChainHash, _short_channel_id: u64) -> UtxoResult {
                UtxoResult::Sync(self.0.clone())
        }
 }
index d2941f7fe3c8f5378f1a16267b076132384b3be2..fbbcc69a133e0966e8bd937d1838ac8dc4fd5c17 100644 (file)
@@ -66,8 +66,8 @@ pub fn scid_from_parts(block: u64, tx_index: u64, vout_index: u64) -> Result<u64
 /// 3) payments intended to be intercepted will route using a fake scid (this is typically used so
 ///    the forwarding node can open a JIT channel to the next hop)
 pub(crate) mod fake_scid {
-       use bitcoin::hash_types::BlockHash;
-       use bitcoin::hashes::hex::FromHex;
+       use bitcoin::blockdata::constants::ChainHash;
+       use bitcoin::network::constants::Network;
        use crate::sign::EntropySource;
        use crate::util::chacha20::ChaCha20;
        use crate::util::scid_utils;
@@ -101,7 +101,7 @@ pub(crate) mod fake_scid {
                /// between segwit activation and the current best known height, and the tx index and output
                /// index are also selected from a "reasonable" range. We add this logic because it makes it
                /// non-obvious at a glance that the scid is fake, e.g. if it appears in invoice route hints.
-               pub(crate) fn get_fake_scid<ES: Deref>(&self, highest_seen_blockheight: u32, genesis_hash: &BlockHash, fake_scid_rand_bytes: &[u8; 32], entropy_source: &ES) -> u64
+               pub(crate) fn get_fake_scid<ES: Deref>(&self, highest_seen_blockheight: u32, chain_hash: &ChainHash, fake_scid_rand_bytes: &[u8; 32], entropy_source: &ES) -> u64
                        where ES::Target: EntropySource,
                {
                        // Ensure we haven't created a namespace that doesn't fit into the 3 bits we've allocated for
@@ -109,7 +109,7 @@ pub(crate) mod fake_scid {
                        assert!((*self as u8) < MAX_NAMESPACES);
                        let rand_bytes = entropy_source.get_secure_random_bytes();
 
-                       let segwit_activation_height = segwit_activation_height(genesis_hash);
+                       let segwit_activation_height = segwit_activation_height(chain_hash);
                        let mut blocks_since_segwit_activation = highest_seen_blockheight.saturating_sub(segwit_activation_height);
 
                        // We want to ensure that this fake channel won't conflict with any transactions we haven't
@@ -144,9 +144,8 @@ pub(crate) mod fake_scid {
                }
        }
 
-       fn segwit_activation_height(genesis: &BlockHash) -> u32 {
-               const MAINNET_GENESIS_STR: &'static str = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
-               if BlockHash::from_hex(MAINNET_GENESIS_STR).unwrap() == *genesis {
+       fn segwit_activation_height(chain_hash: &ChainHash) -> u32 {
+               if *chain_hash == ChainHash::using_genesis_block(Network::Bitcoin) {
                        MAINNET_SEGWIT_ACTIVATION_HEIGHT
                } else {
                        TEST_SEGWIT_ACTIVATION_HEIGHT
@@ -154,28 +153,28 @@ pub(crate) mod fake_scid {
        }
 
        /// Returns whether the given fake scid falls into the phantom namespace.
-       pub fn is_valid_phantom(fake_scid_rand_bytes: &[u8; 32], scid: u64, genesis_hash: &BlockHash) -> bool {
+       pub fn is_valid_phantom(fake_scid_rand_bytes: &[u8; 32], scid: u64, chain_hash: &ChainHash) -> bool {
                let block_height = scid_utils::block_from_scid(&scid);
                let tx_index = scid_utils::tx_index_from_scid(&scid);
                let namespace = Namespace::Phantom;
                let valid_vout = namespace.get_encrypted_vout(block_height, tx_index, fake_scid_rand_bytes);
-               block_height >= segwit_activation_height(genesis_hash)
+               block_height >= segwit_activation_height(chain_hash)
                        && valid_vout == scid_utils::vout_from_scid(&scid) as u8
        }
 
        /// Returns whether the given fake scid falls into the intercept namespace.
-       pub fn is_valid_intercept(fake_scid_rand_bytes: &[u8; 32], scid: u64, genesis_hash: &BlockHash) -> bool {
+       pub fn is_valid_intercept(fake_scid_rand_bytes: &[u8; 32], scid: u64, chain_hash: &ChainHash) -> bool {
                let block_height = scid_utils::block_from_scid(&scid);
                let tx_index = scid_utils::tx_index_from_scid(&scid);
                let namespace = Namespace::Intercept;
                let valid_vout = namespace.get_encrypted_vout(block_height, tx_index, fake_scid_rand_bytes);
-               block_height >= segwit_activation_height(genesis_hash)
+               block_height >= segwit_activation_height(chain_hash)
                        && valid_vout == scid_utils::vout_from_scid(&scid) as u8
        }
 
        #[cfg(test)]
        mod tests {
-               use bitcoin::blockdata::constants::genesis_block;
+               use bitcoin::blockdata::constants::ChainHash;
                use bitcoin::network::constants::Network;
                use crate::util::scid_utils::fake_scid::{is_valid_intercept, is_valid_phantom, MAINNET_SEGWIT_ACTIVATION_HEIGHT, MAX_TX_INDEX, MAX_NAMESPACES, Namespace, NAMESPACE_ID_BITMASK, segwit_activation_height, TEST_SEGWIT_ACTIVATION_HEIGHT};
                use crate::util::scid_utils;
@@ -195,16 +194,16 @@ pub(crate) mod fake_scid {
 
                #[test]
                fn test_segwit_activation_height() {
-                       let mainnet_genesis = genesis_block(Network::Bitcoin).header.block_hash();
+                       let mainnet_genesis = ChainHash::using_genesis_block(Network::Bitcoin);
                        assert_eq!(segwit_activation_height(&mainnet_genesis), MAINNET_SEGWIT_ACTIVATION_HEIGHT);
 
-                       let testnet_genesis = genesis_block(Network::Testnet).header.block_hash();
+                       let testnet_genesis = ChainHash::using_genesis_block(Network::Testnet);
                        assert_eq!(segwit_activation_height(&testnet_genesis), TEST_SEGWIT_ACTIVATION_HEIGHT);
 
-                       let signet_genesis = genesis_block(Network::Signet).header.block_hash();
+                       let signet_genesis = ChainHash::using_genesis_block(Network::Signet);
                        assert_eq!(segwit_activation_height(&signet_genesis), TEST_SEGWIT_ACTIVATION_HEIGHT);
 
-                       let regtest_genesis = genesis_block(Network::Regtest).header.block_hash();
+                       let regtest_genesis = ChainHash::using_genesis_block(Network::Regtest);
                        assert_eq!(segwit_activation_height(&regtest_genesis), TEST_SEGWIT_ACTIVATION_HEIGHT);
                }
 
@@ -212,7 +211,7 @@ pub(crate) mod fake_scid {
                fn test_is_valid_phantom() {
                        let namespace = Namespace::Phantom;
                        let fake_scid_rand_bytes = [0; 32];
-                       let testnet_genesis = genesis_block(Network::Testnet).header.block_hash();
+                       let testnet_genesis = ChainHash::using_genesis_block(Network::Testnet);
                        let valid_encrypted_vout = namespace.get_encrypted_vout(0, 0, &fake_scid_rand_bytes);
                        let valid_fake_scid = scid_utils::scid_from_parts(1, 0, valid_encrypted_vout as u64).unwrap();
                        assert!(is_valid_phantom(&fake_scid_rand_bytes, valid_fake_scid, &testnet_genesis));
@@ -224,7 +223,7 @@ pub(crate) mod fake_scid {
                fn test_is_valid_intercept() {
                        let namespace = Namespace::Intercept;
                        let fake_scid_rand_bytes = [0; 32];
-                       let testnet_genesis = genesis_block(Network::Testnet).header.block_hash();
+                       let testnet_genesis = ChainHash::using_genesis_block(Network::Testnet);
                        let valid_encrypted_vout = namespace.get_encrypted_vout(0, 0, &fake_scid_rand_bytes);
                        let valid_fake_scid = scid_utils::scid_from_parts(1, 0, valid_encrypted_vout as u64).unwrap();
                        assert!(is_valid_intercept(&fake_scid_rand_bytes, valid_fake_scid, &testnet_genesis));
@@ -234,7 +233,7 @@ pub(crate) mod fake_scid {
 
                #[test]
                fn test_get_fake_scid() {
-                       let mainnet_genesis = genesis_block(Network::Bitcoin).header.block_hash();
+                       let mainnet_genesis = ChainHash::using_genesis_block(Network::Bitcoin);
                        let seed = [0; 32];
                        let fake_scid_rand_bytes = [1; 32];
                        let keys_manager = Arc::new(test_utils::TestKeysInterface::new(&seed, Network::Testnet));
index bd66e4cae3e56fa70195a4627bf38451bac37d9c..337dfc063cda3d7254f5625e7390967fde1324ea 100644 (file)
@@ -124,7 +124,7 @@ impl<'a> Router for TestRouter<'a> {
                if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
                        assert_eq!(find_route_query, *params);
                        if let Ok(ref route) = find_route_res {
-                               assert_eq!(route.route_params.as_ref().unwrap().final_value_msat, find_route_query.final_value_msat);
+                               assert_eq!(route.route_params, Some(find_route_query));
                                let scorer = self.scorer.read().unwrap();
                                let scorer = ScorerAccountingForInFlightHtlcs::new(scorer, &inflight_htlcs);
                                for path in &route.paths {
@@ -581,17 +581,17 @@ pub struct TestChannelMessageHandler {
        expected_recv_msgs: Mutex<Option<Vec<wire::Message<()>>>>,
        connected_peers: Mutex<HashSet<PublicKey>>,
        pub message_fetch_counter: AtomicUsize,
-       genesis_hash: ChainHash,
+       chain_hash: ChainHash,
 }
 
 impl TestChannelMessageHandler {
-       pub fn new(genesis_hash: ChainHash) -> Self {
+       pub fn new(chain_hash: ChainHash) -> Self {
                TestChannelMessageHandler {
                        pending_events: Mutex::new(Vec::new()),
                        expected_recv_msgs: Mutex::new(None),
                        connected_peers: Mutex::new(HashSet::new()),
                        message_fetch_counter: AtomicUsize::new(0),
-                       genesis_hash,
+                       chain_hash,
                }
        }
 
@@ -695,8 +695,8 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
                channelmanager::provided_init_features(&UserConfig::default())
        }
 
-       fn get_genesis_hashes(&self) -> Option<Vec<ChainHash>> {
-               Some(vec![self.genesis_hash])
+       fn get_chain_hashes(&self) -> Option<Vec<ChainHash>> {
+               Some(vec![self.chain_hash])
        }
 
        fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
@@ -764,7 +764,7 @@ fn get_dummy_channel_announcement(short_chan_id: u64) -> msgs::ChannelAnnounceme
        let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap();
        let unsigned_ann = msgs::UnsignedChannelAnnouncement {
                features: ChannelFeatures::empty(),
-               chain_hash: genesis_block(network).header.block_hash(),
+               chain_hash: ChainHash::using_genesis_block(network),
                short_channel_id: short_chan_id,
                node_id_1: NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, &node_1_privkey)),
                node_id_2: NodeId::from_pubkey(&PublicKey::from_secret_key(&secp_ctx, &node_2_privkey)),
@@ -790,7 +790,7 @@ fn get_dummy_channel_update(short_chan_id: u64) -> msgs::ChannelUpdate {
        msgs::ChannelUpdate {
                signature: Signature::from(unsafe { FFISignature::new() }),
                contents: msgs::UnsignedChannelUpdate {
-                       chain_hash: genesis_block(network).header.block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(network),
                        short_channel_id: short_chan_id,
                        timestamp: 0,
                        flags: 0,
@@ -866,7 +866,7 @@ impl msgs::RoutingMessageHandler for TestRoutingMessageHandler {
                pending_events.push(events::MessageSendEvent::SendGossipTimestampFilter {
                        node_id: their_node_id.clone(),
                        msg: msgs::GossipTimestampFilter {
-                               chain_hash: genesis_block(Network::Testnet).header.block_hash(),
+                               chain_hash: ChainHash::using_genesis_block(Network::Testnet),
                                first_timestamp: gossip_start_time as u32,
                                timestamp_range: u32::max_value(),
                        },
@@ -969,8 +969,10 @@ impl Logger for TestLogger {
        fn log(&self, record: &Record) {
                *self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
                if record.level >= self.level {
-                       #[cfg(all(not(ldk_bench), feature = "std"))]
-                       println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args);
+                       #[cfg(all(not(ldk_bench), feature = "std"))] {
+                               let pfx = format!("{} {} [{}:{}]", self.id, record.level.to_string(), record.module_path, record.line);
+                               println!("{:<55}{}", pfx, record.args);
+                       }
                }
        }
 }
@@ -1195,7 +1197,7 @@ impl core::fmt::Debug for OnGetShutdownScriptpubkey {
 }
 
 pub struct TestChainSource {
-       pub genesis_hash: BlockHash,
+       pub chain_hash: ChainHash,
        pub utxo_ret: Mutex<UtxoResult>,
        pub get_utxo_call_count: AtomicUsize,
        pub watched_txn: Mutex<HashSet<(Txid, Script)>>,
@@ -1206,7 +1208,7 @@ impl TestChainSource {
        pub fn new(network: Network) -> Self {
                let script_pubkey = Builder::new().push_opcode(opcodes::OP_TRUE).into_script();
                Self {
-                       genesis_hash: genesis_block(network).block_hash(),
+                       chain_hash: ChainHash::using_genesis_block(network),
                        utxo_ret: Mutex::new(UtxoResult::Sync(Ok(TxOut { value: u64::max_value(), script_pubkey }))),
                        get_utxo_call_count: AtomicUsize::new(0),
                        watched_txn: Mutex::new(HashSet::new()),
@@ -1216,9 +1218,9 @@ impl TestChainSource {
 }
 
 impl UtxoLookup for TestChainSource {
-       fn get_utxo(&self, genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
+       fn get_utxo(&self, chain_hash: &ChainHash, _short_channel_id: u64) -> UtxoResult {
                self.get_utxo_call_count.fetch_add(1, Ordering::Relaxed);
-               if self.genesis_hash != *genesis_hash {
+               if self.chain_hash != *chain_hash {
                        return UtxoResult::Sync(Err(UtxoLookupError::UnknownChain));
                }