diff --git a/contrib/download_bitcoind_electrs.sh b/contrib/download_bitcoind_electrs.sh index 8b938a563d3..b279f7dcd19 100755 --- a/contrib/download_bitcoind_electrs.sh +++ b/contrib/download_bitcoind_electrs.sh @@ -10,17 +10,17 @@ HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')" ELECTRS_DL_ENDPOINT="https://github.com/RCasatta/electrsd/releases/download/electrs_releases" ELECTRS_VERSION="esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254" BITCOIND_DL_ENDPOINT="https://bitcoincore.org/bin/" -BITCOIND_VERSION="25.1" +BITCOIND_VERSION="28.1" if [[ "$HOST_PLATFORM" == *linux* ]]; then ELECTRS_DL_FILE_NAME=electrs_linux_"$ELECTRS_VERSION".zip ELECTRS_DL_HASH="865e26a96e8df77df01d96f2f569dcf9622fc87a8d99a9b8fe30861a4db9ddf1" BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-linux-gnu.tar.gz - BITCOIND_DL_HASH="a978c407b497a727f0444156e397b50491ce862d1f906fef9b521415b3611c8b" + BITCOIND_DL_HASH="07f77afd326639145b9ba9562912b2ad2ccec47b8a305bd075b4f4cb127b7ed7" elif [[ "$HOST_PLATFORM" == *darwin* ]]; then ELECTRS_DL_FILE_NAME=electrs_macos_"$ELECTRS_VERSION".zip ELECTRS_DL_HASH="2d5ff149e8a2482d3658e9b386830dfc40c8fbd7c175ca7cbac58240a9505bcd" BITCOIND_DL_FILE_NAME=bitcoin-"$BITCOIND_VERSION"-x86_64-apple-darwin.tar.gz - BITCOIND_DL_HASH="1acfde0ec3128381b83e3e5f54d1c7907871d324549129592144dd12a821eff1" + BITCOIND_DL_HASH="c85d1a0ebedeff43b99db2c906b50f14547b84175a4d0ebb039a9809789af280" else printf "\n\n" echo "Unsupported platform: $HOST_PLATFORM Exiting.." diff --git a/lightning-transaction-sync/Cargo.toml b/lightning-transaction-sync/Cargo.toml index 5e473d31266..c7db8c071a9 100644 --- a/lightning-transaction-sync/Cargo.toml +++ b/lightning-transaction-sync/Cargo.toml @@ -19,23 +19,32 @@ time = [] esplora-async = ["async-interface", "esplora-client/async", "esplora-client/tokio", "futures"] esplora-async-https = ["esplora-async", "esplora-client/async-https-rustls"] esplora-blocking = ["esplora-client/blocking"] -electrum = ["electrum-client"] async-interface = [] +# dummy feature to enable the common codepaths for electrum +_electrum = [] +# the 'default' electrum feature, enabling `rustls` with the `aws-lc-rs` crypto provider +electrum = ["_electrum", "electrum-client/use-rustls"] +electrum-rustls = ["electrum"] + +# this feature enables `rustls` with the `ring` crypto provider +electrum-rustls-ring = ["_electrum", "electrum-client/use-rustls-ring"] + [dependencies] lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["std"] } lightning-macros = { version = "0.2", path = "../lightning-macros", default-features = false } bitcoin = { version = "0.32.2", default-features = false } futures = { version = "0.3", optional = true } esplora-client = { version = "0.11", default-features = false, optional = true } -electrum-client = { version = "0.21.0", optional = true } +electrum-client = { version = "0.22.0", optional = true, default-features = false, features = ["proxy"] } [dev-dependencies] lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["std", "_test_utils"] } tokio = { version = "1.35.0", features = ["macros"] } [target.'cfg(not(target_os = "windows"))'.dev-dependencies] -electrsd = { version = "0.28.0", default-features = false, features = ["legacy"] } +electrsd = { version = "0.33.0", default-features = false, features = ["legacy"] } +corepc-node = { version = "0.7.0", default-features = false, features = ["28_0"] } [lints.rust.unexpected_cfgs] level = "forbid" diff --git a/lightning-transaction-sync/src/error.rs b/lightning-transaction-sync/src/error.rs index 57068b151d2..2fafe50fc16 100644 --- a/lightning-transaction-sync/src/error.rs +++ b/lightning-transaction-sync/src/error.rs @@ -65,14 +65,14 @@ impl From for InternalError { } } -#[cfg(feature = "electrum")] +#[cfg(feature = "_electrum")] impl From for InternalError { fn from(_e: electrum_client::Error) -> Self { Self::Failed } } -#[cfg(feature = "electrum")] +#[cfg(feature = "_electrum")] impl From for TxSyncError { fn from(_e: electrum_client::Error) -> Self { Self::Failed diff --git a/lightning-transaction-sync/src/lib.rs b/lightning-transaction-sync/src/lib.rs index 19ebe007ec2..d221a1d48a8 100644 --- a/lightning-transaction-sync/src/lib.rs +++ b/lightning-transaction-sync/src/lib.rs @@ -74,17 +74,17 @@ #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))] mod esplora; -#[cfg(any(feature = "electrum"))] +#[cfg(any(feature = "_electrum"))] mod electrum; -#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] +#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "_electrum"))] mod common; -#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] +#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "_electrum"))] mod error; -#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum"))] +#[cfg(any(feature = "esplora-blocking", feature = "esplora-async", feature = "_electrum"))] pub use error::TxSyncError; -#[cfg(feature = "electrum")] +#[cfg(feature = "_electrum")] pub use electrum::ElectrumSyncClient; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))] pub use esplora::EsploraSyncClient; diff --git a/lightning-transaction-sync/tests/integration_tests.rs b/lightning-transaction-sync/tests/integration_tests.rs index 0a6f40b0972..b83d27c36ba 100644 --- a/lightning-transaction-sync/tests/integration_tests.rs +++ b/lightning-transaction-sync/tests/integration_tests.rs @@ -1,12 +1,12 @@ #![cfg(all( not(target_os = "windows"), - any(feature = "esplora-blocking", feature = "esplora-async", feature = "electrum") + any(feature = "esplora-blocking", feature = "esplora-async", feature = "_electrum") ))] use lightning::chain::transaction::{OutPoint, TransactionData}; use lightning::chain::{Confirm, Filter, WatchedOutput}; use lightning::util::test_utils::TestLogger; -#[cfg(feature = "electrum")] +#[cfg(feature = "_electrum")] use lightning_transaction_sync::ElectrumSyncClient; #[cfg(any(feature = "esplora-blocking", feature = "esplora-async"))] use lightning_transaction_sync::EsploraSyncClient; @@ -17,9 +17,9 @@ use bitcoin::block::Header; use bitcoin::constants::genesis_block; use bitcoin::network::Network; use bitcoin::{Amount, BlockHash, Txid}; -use bitcoind::bitcoincore_rpc::RpcApi; -use electrsd::bitcoind::bitcoincore_rpc::bitcoincore_rpc_json::AddressType; -use electrsd::{bitcoind, bitcoind::BitcoinD, ElectrsD}; + +use electrsd::corepc_node::Node as BitcoinD; +use electrsd::{corepc_node, ElectrsD}; use std::collections::{HashMap, HashSet}; use std::env; @@ -28,10 +28,10 @@ use std::time::Duration; pub fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) { let bitcoind_exe = - env::var("BITCOIND_EXE").ok().or_else(|| bitcoind::downloaded_exe_path().ok()).expect( + env::var("BITCOIND_EXE").ok().or_else(|| corepc_node::downloaded_exe_path().ok()).expect( "you need to provide an env var BITCOIND_EXE or specify a bitcoind version feature", ); - let mut bitcoind_conf = bitcoind::Conf::default(); + let mut bitcoind_conf = corepc_node::Conf::default(); bitcoind_conf.network = "regtest"; let bitcoind = BitcoinD::with_conf(bitcoind_exe, &bitcoind_conf).unwrap(); @@ -47,14 +47,15 @@ pub fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) { } pub fn generate_blocks_and_wait(bitcoind: &BitcoinD, electrsd: &ElectrsD, num: usize) { - let cur_height = bitcoind.client.get_block_count().expect("failed to get current block height"); - let address = bitcoind + let cur_height = bitcoind .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .expect("failed to get new address") - .assume_checked(); + .get_block_count() + .expect("failed to get current block height") + .into_model() + .0; + let address = bitcoind.client.new_address().expect("failed to get new address"); // TODO: expect this Result once the WouldBlock issue is resolved upstream. - let _block_hashes_res = bitcoind.client.generate_to_address(num as u64, &address); + let _block_hashes_res = bitcoind.client.generate_to_address(num, &address); wait_for_block(electrsd, cur_height as usize + num); } @@ -175,36 +176,20 @@ macro_rules! test_syncing { assert_eq!(events.len(), 1); // Check registered confirmed transactions are marked confirmed - let new_address = $bitcoind - .client - .get_new_address(Some("test"), Some(AddressType::Legacy)) - .unwrap() - .assume_checked(); + let new_address = $bitcoind.client.new_address().unwrap(); let txid = $bitcoind .client - .send_to_address( - &new_address, - Amount::from_sat(5000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&new_address, Amount::from_sat(5000)) + .unwrap() + .0 + .parse() .unwrap(); let second_txid = $bitcoind .client - .send_to_address( - &new_address, - Amount::from_sat(5000), - None, - None, - None, - None, - None, - None, - ) + .send_to_address(&new_address, Amount::from_sat(5000)) + .unwrap() + .0 + .parse() .unwrap(); $tx_sync.register_tx(&txid, &new_address.script_pubkey()); @@ -224,16 +209,12 @@ macro_rules! test_syncing { assert!($confirmable.unconfirmed_txs.lock().unwrap().is_empty()); // Now take an arbitrary output of the second transaction and check we'll confirm its spend. - let tx_res = $bitcoind.client.get_transaction(&second_txid, None).unwrap(); - let block_hash = tx_res.info.blockhash.unwrap(); - let tx = tx_res.transaction().unwrap(); + let tx_res = $bitcoind.client.get_transaction(second_txid).unwrap().into_model().unwrap(); + let block_hash = tx_res.block_hash.unwrap(); + let tx = tx_res.tx; let prev_outpoint = tx.input.first().unwrap().previous_output; - let prev_tx = $bitcoind - .client - .get_transaction(&prev_outpoint.txid, None) - .unwrap() - .transaction() - .unwrap(); + let prev_tx = + $bitcoind.client.get_transaction(prev_outpoint.txid).unwrap().into_model().unwrap().tx; let prev_script_pubkey = prev_tx.output[prev_outpoint.vout as usize].script_pubkey.clone(); let output = WatchedOutput { block_hash: Some(block_hash), @@ -251,19 +232,26 @@ macro_rules! test_syncing { assert!($confirmable.unconfirmed_txs.lock().unwrap().is_empty()); // Check previously confirmed transactions are marked unconfirmed when they are reorged. - let best_block_hash = $bitcoind.client.get_best_block_hash().unwrap(); - $bitcoind.client.invalidate_block(&best_block_hash).unwrap(); + let best_block_hash = + $bitcoind.client.get_best_block_hash().unwrap().into_model().unwrap().0; + $bitcoind.client.invalidate_block(best_block_hash).unwrap(); // We're getting back to the previous height with a new tip, but best block shouldn't change. generate_blocks_and_wait(&$bitcoind, &$electrsd, 1); - assert_ne!($bitcoind.client.get_best_block_hash().unwrap(), best_block_hash); + assert_ne!( + $bitcoind.client.get_best_block_hash().unwrap().into_model().unwrap().0, + best_block_hash + ); maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap(); let events = std::mem::take(&mut *$confirmable.events.lock().unwrap()); assert_eq!(events.len(), 0); // Now we're surpassing previous height, getting new tip. generate_blocks_and_wait(&$bitcoind, &$electrsd, 1); - assert_ne!($bitcoind.client.get_best_block_hash().unwrap(), best_block_hash); + assert_ne!( + $bitcoind.client.get_best_block_hash().unwrap().into_model().unwrap().0, + best_block_hash + ); maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap(); // Transactions still confirmed but under new tip. @@ -344,7 +332,7 @@ async fn test_esplora_syncs() { } #[test] -#[cfg(feature = "electrum")] +#[cfg(feature = "_electrum")] fn test_electrum_syncs() { let (bitcoind, electrsd) = setup_bitcoind_and_electrsd(); generate_blocks_and_wait(&bitcoind, &electrsd, 101);