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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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" + '
Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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('^' + ".*" + ' Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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('^' + ".*" + ' Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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" + ' Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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('^' + ".*" + ' Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading
, '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); } })(); })(); Support new impl traits upstream by TheBlueMatt · Pull Request #696 · lightningdevkit/ldk-node · 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
24 changes: 12 additions & 12 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,17 +39,17 @@ default = []
#lightning-liquidity = { version = "0.2.0", features = ["std"] }
#lightning-macros = { version = "0.2.0" }

lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["tokio"] }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["rest-client", "rpc-client", "tokio"] }
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std"] }
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc" }

bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
Expand DownExpand Up@@ -82,7 +82,7 @@ prost = { version = "0.11.6", default-features = false}
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "bb5504ec62d4b7e9d5626d8b1a6de60d71e8d370", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "5bf0d1e2427d759fc1ba4108ddc7e9b32e8bacfc", features = ["std", "_test_utils"] }
proptest = "1.0.0"
regex = "1.5.6"
criterion = { version = "0.7.0", features = ["async_tokio"] }
Expand Down
38 changes: 19 additions & 19 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,8 @@ use crate::peer_store::PeerStore;
use crate::runtime::Runtime;
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
OnionMessenger, PaymentStore, PeerManager, Persister,
ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph, KeysManager,
MessageRouter, OnionMessenger, PaymentStore, PeerManager, Persister, SyncAndAsyncKVStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -544,14 +544,12 @@ impl NodeBuilder {
let storage_dir_path = self.config.storage_dir_path.clone();
fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(
SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?,
);
let kv_store = SqliteStore::new(
storage_dir_path.into(),
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
)
.map_err(|_| BuildError::KVStoreSetupFailed)?;
self.build_with_store(node_entropy, kv_store)
}

Expand All@@ -563,7 +561,7 @@ impl NodeBuilder {

fs::create_dir_all(storage_dir_path.clone())
.map_err(|_| BuildError::StoragePathAccessFailed)?;
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
let kv_store = FilesystemStore::new(storage_dir_path);
self.build_with_store(node_entropy, kv_store)
}

Expand DownExpand Up@@ -595,7 +593,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -622,7 +620,7 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand All@@ -647,12 +645,12 @@ impl NodeBuilder {
BuildError::KVStoreSetupFailed
})?;

self.build_with_store(node_entropy, Arc::new(vss_store))
self.build_with_store(node_entropy, vss_store)
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: NodeEntropy, kv_store: Arc<DynStore>,
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S,
) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;

Expand All@@ -678,7 +676,7 @@ impl NodeBuilder {
seed_bytes,
runtime,
logger,
kv_store,
Arc::new(DynStoreWrapper(kv_store)),
)
}
}
Expand DownExpand Up@@ -1014,8 +1012,10 @@ impl ArcedNodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store(
&self, node_entropy: Arc<NodeEntropy>, kv_store: Arc<DynStore>,
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
// this so its not needed.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
}
Expand Down
137 changes: 105 additions & 32 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,13 +6,14 @@
// accordance with one or both of these licenses.

use std::collections::{HashMap, VecDeque};
use std::future::Future;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bitcoin::{BlockHash, FeeRate, Network, Transaction, Txid};
use bitcoin::{BlockHash, FeeRate, Network, OutPoint, Transaction, Txid};
use lightning::chain::chaininterface::ConfirmationTarget as LdkConfirmationTarget;
use lightning::chain::{BestBlock, Listen};
use lightning::util::ser::Writeable;
Expand All@@ -23,7 +24,7 @@ use lightning_block_sync::poll::{ChainPoller, ChainTip, ValidatedBlockHeader};
use lightning_block_sync::rest::RestClient;
use lightning_block_sync::rpc::{RpcClient, RpcError};
use lightning_block_sync::{
AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource, BlockSourceErrorKind, Cache,
BlockData, BlockHeaderData, BlockSource, BlockSourceError, BlockSourceErrorKind, Cache,
SpvClient,
};
use serde::Serialize;
Expand DownExpand Up@@ -117,7 +118,7 @@ impl BitcoindChainSource {
}
}

pub(super) fn as_utxo_source(&self) -> Arc<dyn UtxoSource> {
pub(super) fn as_utxo_source(&self) -> UtxoSourceClient {
self.api_client.utxo_source()
}

Expand DownExpand Up@@ -639,6 +640,78 @@ impl BitcoindChainSource {
}
}

#[derive(Clone)]
pub(crate) enum UtxoSourceClient {
Rpc(Arc<RpcClient>),
Rest(Arc<RestClient>),
}

impl std::ops::Deref for UtxoSourceClient {
type Target = Self;
fn deref(&self) -> &Self {
self
}
}

impl BlockSource for UtxoSourceClient {
fn get_header<'a>(
&'a self, header_hash: &'a BlockHash, height_hint: Option<u32>,
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_header(header_hash, height_hint).await,
Self::Rest(client) => client.get_header(header_hash, height_hint).await,
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a BlockHash,
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block(header_hash).await,
Self::Rest(client) => client.get_block(header_hash).await,
}
}
}

fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_best_block().await,
Self::Rest(client) => client.get_best_block().await,
}
}
}
}

impl UtxoSource for UtxoSourceClient {
fn get_block_hash_by_height<'a>(
&'a self, block_height: u32,
) -> impl Future<Output = Result<BlockHash, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.get_block_hash_by_height(block_height).await,
Self::Rest(client) => client.get_block_hash_by_height(block_height).await,
}
}
}

fn is_output_unspent<'a>(
&'a self, outpoint: OutPoint,
) -> impl Future<Output = Result<bool, BlockSourceError>> + 'a {
async move {
match self {
Self::Rpc(client) => client.is_output_unspent(outpoint).await,
Self::Rest(client) => client.is_output_unspent(outpoint).await,
}
}
}
}

pub enum BitcoindClient {
Rpc {
rpc_client: Arc<RpcClient>,
Expand DownExpand Up@@ -700,12 +773,10 @@ impl BitcoindClient {
}
}

pub(crate) fn utxo_source(&self) -> Arc<dyn UtxoSource> {
fn utxo_source(&self) -> UtxoSourceClient {
match self {
BitcoindClient::Rpc { rpc_client, .. } => Arc::clone(rpc_client) as Arc<dyn UtxoSource>,
BitcoindClient::Rest { rest_client, .. } => {
Arc::clone(rest_client) as Arc<dyn UtxoSource>
},
Self::Rpc { rpc_client, .. } => UtxoSourceClient::Rpc(Arc::clone(&rpc_client)),
Self::Rest { rest_client, .. } => UtxoSourceClient::Rest(Arc::clone(&rest_client)),
}
}

Expand DownExpand Up@@ -1189,38 +1260,40 @@ impl BitcoindClient {
impl BlockSource for BitcoindClient {
fn get_header<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash, height_hint: Option<u32>,
) -> AsyncBlockSourceResult<'a, BlockHeaderData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
},
) -> impl Future<Output = Result<BlockHeaderData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
rpc_client.get_header(header_hash, height_hint).await
},
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_header(header_hash, height_hint).await
},
}
}
}

fn get_block<'a>(
&'a self, header_hash: &'a bitcoin::BlockHash,
) -> AsyncBlockSourceResult<'a, BlockData> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_block(header_hash).await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_block(header_hash).await })
},
) -> impl Future<Output = Result<BlockData, BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_block(header_hash).await,
BitcoindClient::Rest { rest_client, .. } => {
rest_client.get_block(header_hash).await
},
}
}
}

fn get_best_block(&self) -> AsyncBlockSourceResult<'_, (bitcoin::BlockHash, Option<u32>)> {
match self {
BitcoindClient::Rpc { rpc_client, .. } => {
Box::pin(async move { rpc_client.get_best_block().await })
},
BitcoindClient::Rest { rest_client, .. } => {
Box::pin(async move { rest_client.get_best_block().await })
},
fn get_best_block<'a>(
&'a self,
) -> impl Future<Output = Result<(bitcoin::BlockHash, Option<u32>), BlockSourceError>> + 'a {
async move {
match self {
BitcoindClient::Rpc { rpc_client, .. } => rpc_client.get_best_block().await,
BitcoindClient::Rest { rest_client, .. } => rest_client.get_best_block().await,
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/chain/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

mod bitcoind;
pub(crate) mod bitcoind;
mod electrum;
mod esplora;

Expand All@@ -15,9 +15,8 @@ use std::time::Duration;

use bitcoin::{Script, Txid};
use lightning::chain::{BestBlock, Filter};
use lightning_block_sync::gossip::UtxoSource;

use crate::chain::bitcoind::BitcoindChainSource;
use crate::chain::bitcoind::{BitcoindChainSource, UtxoSourceClient};
use crate::chain::electrum::ElectrumChainSource;
use crate::chain::esplora::EsploraChainSource;
use crate::config::{
Expand DownExpand Up@@ -202,7 +201,7 @@ impl ChainSource {
}
}

pub(crate) fn as_utxo_source(&self) -> Option<Arc<dyn UtxoSource>> {
pub(crate) fn as_utxo_source(&self) -> Option<UtxoSourceClient> {
match &self.kind {
ChainSourceKind::Bitcoind(bitcoind_chain_source) => {
Some(bitcoind_chain_source.as_utxo_source())
Expand Down
3 changes: 2 additions & 1 deletion src/data_store.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,6 +177,7 @@ mod tests {
use super::*;
use crate::hex_utils;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
struct TestObjectId {
Expand DownExpand Up@@ -235,7 +236,7 @@ mod tests {

#[test]
fn data_is_persisted() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let primary_namespace = "datastore_test_primary".to_string();
let secondary_namespace = "datastore_test_secondary".to_string();
Expand Down
5 changes: 3 additions & 2 deletions src/event.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -1801,10 +1801,11 @@ mod tests {

use super::*;
use crate::io::test_utils::InMemoryStore;
use crate::types::DynStoreWrapper;

#[tokio::test]
async fn event_queue_persistence() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand DownExpand Up@@ -1842,7 +1843,7 @@ mod tests {

#[tokio::test]
async fn event_queue_concurrency() {
let store: Arc<DynStore> = Arc::new(InMemoryStore::new());
let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new()));
let logger = Arc::new(TestLogger::new());
let event_queue = Arc::new(EventQueue::new(Arc::clone(&store), Arc::clone(&logger)));
assert_eq!(event_queue.next_event(), None);
Expand Down
Loading