From cae92e8b151d8459fee7a7eb0b823c25951363f5 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 4 May 2021 17:44:04 +0000 Subject: [PATCH] Check that the node we connect to matches the user-provided chain --- src/convert.rs | 2 ++ src/main.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/convert.rs b/src/convert.rs index 7dbd8cc..a652980 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -72,6 +72,7 @@ impl TryInto for JsonResponse { pub struct BlockchainInfo { pub latest_height: usize, pub latest_blockhash: BlockHash, + pub chain: String, } impl TryInto for JsonResponse { @@ -81,6 +82,7 @@ impl TryInto for JsonResponse { latest_height: self.0["blocks"].as_u64().unwrap() as usize, latest_blockhash: BlockHash::from_hex(self.0["bestblockhash"].as_str().unwrap()) .unwrap(), + chain: self.0["chain"].as_str().unwrap().to_string(), }) } } diff --git a/src/main.rs b/src/main.rs index 21dfb28..7f4b5bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -290,6 +290,18 @@ async fn start_ldk() { } }; + // Check that the bitcoind we've connected to is running the network we expect + let bitcoind_chain = bitcoind_client.get_blockchain_info().await.chain; + if bitcoind_chain != match args.network { + bitcoin::Network::Bitcoin => "main", + bitcoin::Network::Testnet => "test", + bitcoin::Network::Regtest => "regtest", + bitcoin::Network::Signet => "signet", + } { + println!("Chain argument ({}) didn't match bitcoind chain ({})", args.network, bitcoind_chain); + return; + } + // ## Setup // Step 1: Initialize the FeeEstimator -- 2.30.2