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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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" + '
Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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('^' + ".*" + ' Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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('^' + ".*" + ' Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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" + ' Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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('^' + ".*" + ' Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
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); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Fully switch to async `KVStore` persistence by tnull · Pull Request #919 · 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
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,4 +43,4 @@ jobs:
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
- name: Run benchmarks
run: |
cargo bench
RUSTFLAGS="--cfg tokio_unstable" cargo bench
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -84,7 +84,7 @@ jobs:
- name: Test on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest'"
run: |
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
run: |
Expand DownExpand Up@@ -114,4 +114,4 @@ jobs:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-docs-rs
- run: cargo docs-rs
- run: cargo docs-rs
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
#lightning-macros = { version = "0.2.0" }
#lightning-dns-resolver = { version = "0.3.0" }

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

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@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
vss-client = { package = "vss-client-ng", version = "0.5" }
prost = { version = "0.11.6", default-features = false}
#bitcoin-payment-instructions = { version = "0.6" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase"] }

[dev-dependencies]
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
proptest = "1.0.0"
regex = "1.5.6"
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_kotlin.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
PACKAGE_DIR="org/lightningdevkit/ldknode"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
rustup target add x86_64-unknown-linux-gnu || exit 1
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
Expand Down
11 changes: 8 additions & 3 deletions scripts/uniffi_bindgen_generate_kotlin_android.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,11 @@ TARGET_DIR="target"
PROJECT_DIR="ldk-node-android"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

export_variable_if_not_present() {
local name="$1"
local value="$2"
Expand DownExpand Up@@ -35,9 +40,9 @@ case "$OSTYPE" in
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"

rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="-C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target x86_64-linux-android || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --profile release-smaller --features uniffi --target armv7-linux-androideabi || exit 1
RUSTFLAGS="$RUSTFLAGS_WITH_TOKIO_UNSTABLE -C link-args=-Wl,-z,max-page-size=16384,-z,common-page-size=16384" CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=21" AR=llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --profile release-smaller --features uniffi --target aarch64-linux-android || exit 1
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --lib-file "$TARGET_DIR"/x86_64-linux-android/release-smaller/libldk_node.so --language kotlin --config uniffi-android.toml -o "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin || exit 1

JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_python.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,11 @@
BINDINGS_DIR="./bindings/python/src/ldk_node"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
else
Expand Down
5 changes: 5 additions & 0 deletions scripts/uniffi_bindgen_generate_swift.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ set -eox pipefail
BINDINGS_DIR="./bindings/swift"
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"

case " ${RUSTFLAGS:-} " in
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
esac

mkdir -p $BINDINGS_DIR

# Install rust target toolchains
Expand Down
54 changes: 32 additions & 22 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
PeerManager, PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
use crate::{Node, NodeMetrics};
use crate::{Node, NodeMetrics, PersistedNodeMetrics};

const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
Expand DownExpand Up@@ -176,17 +176,17 @@ pub enum BuildError {
RuntimeSetupFailed,
/// We failed to read data from the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
ReadFailed,
/// We failed to write data to the [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
WriteFailed,
/// We failed to access the given `storage_dir_path`.
StoragePathAccessFailed,
/// We failed to setup our [`KVStore`].
///
/// [`KVStore`]: lightning::util::persist::KVStoreSync
/// [`KVStore`]: lightning::util::persist::KVStore
KVStoreSetupFailed,
/// We failed to setup the onchain wallet.
WalletSetupFailed,
Expand DownExpand Up@@ -697,11 +697,12 @@ impl NodeBuilder {
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
let logger = setup_logger(&self.log_writer_config, &self.config)?;
let runtime = self.setup_runtime(&logger)?;
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
storage_dir_path.push("fs_store");

let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
self.build_with_store_and_logger(node_entropy, kv_store, logger)
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

/// Builds a [`Node`] instance with a [VSS] backend and according to the options
Expand DownExpand Up@@ -825,7 +826,7 @@ impl NodeBuilder {
}

/// Builds a [`Node`] instance according to the options previously configured.
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
pub fn build_with_store<S: KVStore + 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@@ -844,14 +845,14 @@ impl NodeBuilder {
}
}

fn build_with_store_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let runtime = self.setup_runtime(&logger)?;
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
}

fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
) -> Result<Node, BuildError> {
let seed_bytes = node_entropy.to_seed_bytes();
Expand DownExpand Up@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
/// Builds a [`Node`] instance according to the options previously configured.
// 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>(
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
) -> Result<Arc<Node>, BuildError> {
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1415,10 +1416,10 @@ fn build_with_store_internal(

// Initialize the status fields.
let node_metrics = match node_metris_res {
Ok(metrics) => Arc::new(RwLock::new(metrics)),
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
Err(e) => {
if e.kind() == std::io::ErrorKind::NotFound {
Arc::new(RwLock::new(NodeMetrics::default()))
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
} else {
log_error!(logger, "Failed to read node metrics from store: {}", e);
return Err(BuildError::ReadFailed);
Expand DownExpand Up@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
let mut wallet_persister =
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
let wallet_opt = BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet(&mut wallet_persister)
let wallet_opt = runtime
.block_on(async {
BdkWallet::load()
.descriptor(KeychainKind::External, Some(descriptor.clone()))
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
.extract_keys()
.check_network(config.network)
.load_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
let bdk_wallet = match wallet_opt {
Some(wallet) => wallet,
None => {
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet(&mut wallet_persister)
let mut wallet = runtime
.block_on(async {
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister)
.await
})
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
Arc::clone(&fee_estimator),
Arc::clone(&chain_source),
Arc::clone(&payment_store),
Arc::clone(&runtime),
Arc::clone(&config),
Arc::clone(&logger),
Arc::clone(&pending_payment_store),
Expand Down
15 changes: 9 additions & 6 deletions src/chain/bitcoind.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -42,7 +42,7 @@ use crate::fee_estimator::{
use crate::io::utils::update_and_persist_node_metrics;
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
use crate::{Error, NodeMetrics};
use crate::{Error, PersistedNodeMetrics};

const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
Expand All@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
kv_store: Arc<DynStore>,
config: Arc<Config>,
logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
}

impl BitcoindChainSource {
pub(crate) fn new_rpc(
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rpc(
rpc_host.clone(),
Expand All@@ -89,7 +89,7 @@ impl BitcoindChainSource {
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
node_metrics: Arc<RwLock<NodeMetrics>>,
node_metrics: Arc<PersistedNodeMetrics>,
) -> Self {
let api_client = Arc::new(BitcoindClient::new_rest(
rest_client_config.rest_host,
Expand DownExpand Up@@ -204,6 +204,7 @@ impl BitcoindChainSource {
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
},
)
.await
.unwrap_or_else(|e| {
log_error!(self.logger, "Failed to persist node metrics: {}", e);
});
Expand DownExpand Up@@ -451,7 +452,8 @@ impl BitcoindChainSource {
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
})?;
})
.await?;

Ok(())
}
Expand DownExpand Up@@ -563,7 +565,8 @@ impl BitcoindChainSource {
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
})?;
})
.await?;

Ok(())
}
Expand Down
Loading