Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Bump `electrum_client` dependency and add new TLS-backend features by tnull · Pull Request #3587 · lightningdevkit/rust-lightning · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/download_bitcoind_electrs.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.."
Expand Down
15 changes: 12 additions & 3 deletions lightning-transaction-sync/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"]
Comment thread
wpaulino marked this conversation as resolved.

# 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"] }
Comment thread
tnull marked this conversation as resolved.

[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"
Expand Down
4 changes: 2 additions & 2 deletions lightning-transaction-sync/src/error.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,14 +65,14 @@ impl From<esplora_client::Error> for InternalError {
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for InternalError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
}
}

#[cfg(feature = "electrum")]
#[cfg(feature = "_electrum")]
impl From<electrum_client::Error> for TxSyncError {
fn from(_e: electrum_client::Error) -> Self {
Self::Failed
Expand Down
10 changes: 5 additions & 5 deletions lightning-transaction-sync/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -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;
92 changes: 40 additions & 52 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line numberDiff line numberDiff line change
@@ -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;
Expand All@@ -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;
Expand All@@ -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();

Expand All@@ -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);
}

Expand DownExpand Up@@ -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());

Expand All@@ -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),
Expand All@@ -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,
Comment thread
tnull marked this conversation as resolved.
best_block_hash
);
maybe_await!($tx_sync.sync(vec![&$confirmable])).unwrap();

// Transactions still confirmed but under new tip.
Expand DownExpand Up@@ -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);
Expand Down