From 9211d849c191ff5d2552bde681edaa7038c8d049 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 13 Dec 2022 16:04:34 +0100 Subject: [PATCH 1/3] bitcoind: be less stupid when loading the watchonly wallet Only load it if isn't there already. --- src/bitcoin/d/mod.rs | 17 ++++++++--------- src/lib.rs | 13 ++++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/bitcoin/d/mod.rs b/src/bitcoin/d/mod.rs index 2d917fc7..412abaea 100644 --- a/src/bitcoin/d/mod.rs +++ b/src/bitcoin/d/mod.rs @@ -553,16 +553,15 @@ impl BitcoinD { Ok(()) } - /// Try to load the watchonly wallet in bitcoind. It will continue on error (since it's - /// likely the wallet is just already loaded) and log it as info instead. - pub fn try_load_watchonly_wallet(&self) { - // TODO: check if it's not loaded instead of blindly trying to load it. - if let Err(e) = self.make_fallible_node_request( - "loadwallet", - ¶ms!(Json::String(self.watchonly_wallet_path.clone()),), - ) { - log::info!("Got error '{}' while trying to load watchonly on bitcoind. It is possibly already loaded.", e); + /// Load the watchonly wallet on bitcoind, if it isn't already. + pub fn maybe_load_watchonly_wallet(&self) -> Result<(), BitcoindError> { + if !self.list_wallets().contains(&self.watchonly_wallet_path) { + self.make_fallible_node_request( + "loadwallet", + ¶ms!(Json::String(self.watchonly_wallet_path.clone()),), + )?; } + Ok(()) } /// Perform various sanity checks on the bitcoind instance. diff --git a/src/lib.rs b/src/lib.rs index a2cb7319..ec96ad09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,7 +203,7 @@ fn setup_bitcoind( bitcoind.create_watchonly_wallet(&config.main_descriptor)?; log::info!("Created a new watchonly wallet on bitcoind."); } - bitcoind.try_load_watchonly_wallet(); + bitcoind.maybe_load_watchonly_wallet()?; bitcoind.sanity_check(&config.main_descriptor, config.bitcoin_config.network)?; log::info!("Connection to bitcoind established and checked."); @@ -488,12 +488,19 @@ mod tests { // Send them a dummy result to loadwallet. fn complete_wallet_loading(server: &net::TcpListener) { - let net_resp = + let listwallets_resp = + "HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":[]}\n".as_bytes(); + let (mut stream, _) = server.accept().unwrap(); + read_til_json_end(&mut stream); + stream.write_all(listwallets_resp).unwrap(); + stream.flush().unwrap(); + + let loadwallet_resp = "HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"name\":\"dummy\"}}\n" .as_bytes(); let (mut stream, _) = server.accept().unwrap(); read_til_json_end(&mut stream); - stream.write_all(net_resp).unwrap(); + stream.write_all(loadwallet_resp).unwrap(); stream.flush().unwrap(); } From 650101525d890f50290989bd58c367024a69115c Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 13 Dec 2022 16:10:22 +0100 Subject: [PATCH 2/3] bitcoind: set minimum required version to 24.0 --- .cirrus.yml | 9 ++++----- src/bitcoin/d/mod.rs | 2 +- src/lib.rs | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 95f3413f..3857f2dd 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -43,11 +43,10 @@ task: set -xe # Download the bitcoind binary - # TODO: cleanup by using env variables like in revaultd once 24.0 is out. - ARCHIVE_NAME="bitcoin-core-24.0rc1.tar.gz" - curl https://bitcoincore.org/bin/bitcoin-core-24.0/test.rc1/bitcoin-24.0rc1-x86_64-linux-gnu.tar.gz -o $ARCHIVE_NAME - tar -xzf $ARCHIVE_NAME - export BITCOIND_PATH=bitcoin-24.0rc1/bin/bitcoind + curl -O https://bitcoincore.org/bin/bitcoin-core-24.0.1/bitcoin-24.0.1-x86_64-linux-gnu.tar.gz + echo "49df6e444515d457ea0b885d66f521f2a26ca92ccf73d5296082e633544253bf bitcoin-24.0.1-x86_64-linux-gnu.tar.gz" | sha256sum -c + tar -xzf bitcoin-24.0.1-x86_64-linux-gnu.tar.gz + export BITCOIND_PATH=bitcoin-24.0.1/bin/bitcoind # Run the functional tests LIANAD_PATH=$PWD/target/release/lianad pytest $TEST_GROUP -vvv -n 2 diff --git a/src/bitcoin/d/mod.rs b/src/bitcoin/d/mod.rs index 412abaea..2978564e 100644 --- a/src/bitcoin/d/mod.rs +++ b/src/bitcoin/d/mod.rs @@ -35,7 +35,7 @@ const RPC_SOCKET_TIMEOUT: u64 = 180; const BITCOIND_RETRY_LIMIT: usize = 60; // The minimum bitcoind version that can be used with lianad. -const MIN_BITCOIND_VERSION: u64 = 239900; +const MIN_BITCOIND_VERSION: u64 = 240000; /// An error in the bitcoind interface. #[derive(Debug)] diff --git a/src/lib.rs b/src/lib.rs index ec96ad09..a12932f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -433,10 +433,10 @@ mod tests { stream.flush().unwrap(); } - // Send them a pruned getblockchaininfo telling them we are at version 23.99 + // Send them a pruned getblockchaininfo telling them we are at version 24.0 fn complete_version_check(server: &net::TcpListener) { let net_resp = - "HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"version\":239900}}\n" + "HTTP/1.1 200\n\r\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"version\":240000}}\n" .as_bytes(); let (mut stream, _) = server.accept().unwrap(); read_til_json_end(&mut stream); From acd6929831964d643565f8f22b552f74613a3a1d Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 13 Dec 2022 16:12:07 +0100 Subject: [PATCH 3/3] doc: update for bitcoind 24.0.1 release Technically the minimum we support is 24.0 but let's not nudge people to install a version with a buggy wallet. Fixes #210 --- README.md | 2 +- doc/TRY.md | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 34834913..c8be08d9 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Therefore in order to use Liana you need to have Bitcoin Core running on your ma desired network. The `bitcoind` installation may be pruned (note this may affect block chain rescans) up to the maximum (around 550MB of blocks). -The minimum supported version of Bitcoin Core is `24.0`. If you don't have Bitcoin Core installed on +The minimum supported version of Bitcoin Core is `24.0.1`. If you don't have Bitcoin Core installed on your machine yet, you can download it [there](https://bitcoincore.org/en/download/). ### Installing the software diff --git a/doc/TRY.md b/doc/TRY.md index 5bdca529..bdd01744 100644 --- a/doc/TRY.md +++ b/doc/TRY.md @@ -45,15 +45,13 @@ cd liana_quicktry ## Step 1: setup `bitcoind` -Liana needs `bitcoind` to communicate with the Bitcoin network. Minimum supported version is 24.0. +Liana needs `bitcoind` to communicate with the Bitcoin network. Minimum supported version is 24.0.1. ### Download -TODO: update to 24.0.1 when it's released. - Download the `bitcoind` binary from [the official website of the Bitcoin Core -project](https://bitcoincore.org/bin/bitcoin-core-24.0/) according to your platform (in the context -of this guide, it is most likely `bitcoin-24.0-x86_64-linux-gnu.tar.gz`). +project](https://bitcoincore.org/bin/bitcoin-core-24.0.1/) according to your platform (in the context +of this guide, it is most likely `bitcoin-24.0.1-x86_64-linux-gnu.tar.gz`). Then verify the signature against a key you trust. The Bitcoin Core Github repo contains [a list](https://github.com/bitcoin/bitcoin/blob/master/contrib/builder-keys/keys.txt) of frequent @@ -62,11 +60,11 @@ signers. Mine is `590B7292695AFFA5B672CBB2E13FC145CD3F4304`. Finally, uncompress the archive to get access to the `bitcoind` binary. ``` -curl -O https://bitcoincore.org/bin/bitcoin-core-24.0/bitcoin-24.0-x86_64-linux-gnu.tar.gz -O https://bitcoincore.org/bin/bitcoin-core-24.0/SHA256SUMS -O https://bitcoincore.org/bin/bitcoin-core-24.0/SHA256SUMS.asc +curl -O https://bitcoincore.org/bin/bitcoin-core-24.0.1/bitcoin-24.0.1-x86_64-linux-gnu.tar.gz -O https://bitcoincore.org/bin/bitcoin-core-24.0.1/SHA256SUMS -O https://bitcoincore.org/bin/bitcoin-core-24.0/SHA256SUMS.asc sha256sum --ignore-missing --check SHA256SUMS gpg --keyserver hkps://keys.openpgp.org --receive 590B7292695AFFA5B672CBB2E13FC145CD3F4304 gpg --verify SHA256SUMS.asc -tar -xzf bitcoin-24.0-x86_64-linux-gnu.tar.gz +tar -xzf bitcoin-24.0.1-x86_64-linux-gnu.tar.gz ``` For details on verifying your download, or for verifying the download on a non-Linux machine refer @@ -77,14 +75,14 @@ to Run `bitcoind` in the background on the public signet network. ``` -./bitcoin-24.0/bin/bitcoind -signet -daemon +./bitcoin-24.0.1/bin/bitcoind -signet -daemon ``` If it is the first time you start a signet Bitcoin on this machine it will take a few minutes to synchronize (depends on your connection and hardware of course, but it shouldn't take longer than a handful of minutes). You can track the progress using the `getblockchaininfo` command: ``` -./bitcoin-24.0/bin/bitcoin-cli -signet getblockchaininfo +./bitcoin-24.0.1/bin/bitcoin-cli -signet getblockchaininfo ``` You do not need to wait for full synchronisation before moving on to the next step.