Skip to content

Commit 00dba45

Browse files
authored
Merge pull request #919 from tnull/2026-06-async-kvstore-persistence
Fully switch to async `KVStore` persistence
2 parents 47dad6d + a3e7653 commit 00dba45

33 files changed

Lines changed: 1485 additions & 1314 deletions

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ jobs:
4343
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
4444
- name: Run benchmarks
4545
run: |
46-
cargo bench
46+
RUSTFLAGS="--cfg tokio_unstable" cargo bench

.github/workflows/rust.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Test on Rust ${{ matrix.toolchain }}
8585
if: "matrix.platform != 'windows-latest'"
8686
run: |
87-
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test
87+
RUSTFLAGS="--cfg no_download --cfg cycle_tests --cfg tokio_unstable" cargo test
8888
- name: Test with UniFFI support on Rust ${{ matrix.toolchain }}
8989
if: "matrix.platform != 'windows-latest' && matrix.build-uniffi"
9090
run: |
@@ -114,4 +114,4 @@ jobs:
114114
- uses: actions/checkout@v6
115115
- uses: dtolnay/rust-toolchain@nightly
116116
- uses: dtolnay/install@cargo-docs-rs
117-
- run: cargo docs-rs
117+
- run: cargo docs-rs

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ postgres = ["dep:tokio-postgres", "dep:native-tls", "dep:postgres-native-tls"]
4141
#lightning-macros = { version = "0.2.0" }
4242
#lightning-dns-resolver = { version = "0.3.0" }
4343

44-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std"] }
45-
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
46-
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std"] }
47-
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
48-
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["tokio"] }
49-
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
50-
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
51-
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["rest-client", "rpc-client", "tokio"] }
52-
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
53-
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std"] }
54-
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
55-
lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182" }
44+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std"] }
45+
lightning-types = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
46+
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std"] }
47+
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
48+
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["tokio"] }
49+
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
50+
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
51+
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["rest-client", "rpc-client", "tokio"] }
52+
lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
53+
lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std"] }
54+
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
55+
lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
5656

5757
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
5858
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -85,13 +85,13 @@ postgres-native-tls = { version = "0.5", default-features = false, features = ["
8585
vss-client = { package = "vss-client-ng", version = "0.5" }
8686
prost = { version = "0.11.6", default-features = false}
8787
#bitcoin-payment-instructions = { version = "0.6" }
88-
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ed8657dee284f987b6791cd291d0f0f18811ee76" }
88+
bitcoin-payment-instructions = { git = "https://github.com/tnull/bitcoin-payment-instructions", rev = "ff09ce9401afa448549a8f101172700bcd14d7bb" }
8989

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

9393
[dev-dependencies]
94-
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "090e09f3992694040d3a55c1c798b3a92fb77182", features = ["std", "_test_utils"] }
94+
lightning = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c", features = ["std", "_test_utils"] }
9595
rand = { version = "0.9.2", default-features = false, features = ["std", "thread_rng", "os_rng"] }
9696
proptest = "1.0.0"
9797
regex = "1.5.6"

scripts/uniffi_bindgen_generate_kotlin.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ PROJECT_DIR="ldk-node-jvm"
55
PACKAGE_DIR="org/lightningdevkit/ldknode"
66
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"
77

8+
case " ${RUSTFLAGS:-} " in
9+
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
10+
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
11+
esac
12+
813
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
914
rustup target add x86_64-unknown-linux-gnu || exit 1
1015
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1

scripts/uniffi_bindgen_generate_kotlin_android.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ TARGET_DIR="target"
55
PROJECT_DIR="ldk-node-android"
66
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"
77

8+
case " ${RUSTFLAGS:-} " in
9+
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:-}" ;;
10+
*) RUSTFLAGS_WITH_TOKIO_UNSTABLE="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
11+
esac
12+
813
export_variable_if_not_present() {
914
local name="$1"
1015
local value="$2"
@@ -35,9 +40,9 @@ case "$OSTYPE" in
3540
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$LLVM_ARCH_PATH/bin:$PATH"
3641

3742
rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
38-
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
39-
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
40-
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
43+
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
44+
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
45+
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
4146
$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
4247

4348
JNI_LIB_DIR="$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/jniLibs/

scripts/uniffi_bindgen_generate_python.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
BINDINGS_DIR="./bindings/python/src/ldk_node"
33
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"
44

5+
case " ${RUSTFLAGS:-} " in
6+
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
7+
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
8+
esac
9+
510
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
611
DYNAMIC_LIB_PATH="./target/release-smaller/libldk_node.so"
712
else

scripts/uniffi_bindgen_generate_swift.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -eox pipefail
44
BINDINGS_DIR="./bindings/swift"
55
UNIFFI_BINDGEN_BIN="cargo run --manifest-path bindings/uniffi-bindgen/Cargo.toml"
66

7+
case " ${RUSTFLAGS:-} " in
8+
*" --cfg tokio_unstable "*|*" --cfg=tokio_unstable "*) ;;
9+
*) export RUSTFLAGS="${RUSTFLAGS:+$RUSTFLAGS }--cfg tokio_unstable" ;;
10+
esac
11+
712
mkdir -p $BINDINGS_DIR
813

914
# Install rust target toolchains

src/builder.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ use crate::tx_broadcaster::TransactionBroadcaster;
8181
use crate::types::{
8282
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
8383
GossipSync, Graph, HRNResolver, KeysManager, MessageRouter, OnionMessenger, PaymentStore,
84-
PeerManager, PendingPaymentStore, SyncAndAsyncKVStore,
84+
PeerManager, PendingPaymentStore,
8585
};
8686
use crate::wallet::persist::KVStoreWalletPersister;
8787
use crate::wallet::Wallet;
88-
use crate::{Node, NodeMetrics};
88+
use crate::{Node, NodeMetrics, PersistedNodeMetrics};
8989

9090
const LSPS_HARDENED_CHILD_INDEX: u32 = 577;
9191
const PERSISTER_MAX_PENDING_UPDATES: u64 = 100;
@@ -176,17 +176,17 @@ pub enum BuildError {
176176
RuntimeSetupFailed,
177177
/// We failed to read data from the [`KVStore`].
178178
///
179-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
179+
/// [`KVStore`]: lightning::util::persist::KVStore
180180
ReadFailed,
181181
/// We failed to write data to the [`KVStore`].
182182
///
183-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
183+
/// [`KVStore`]: lightning::util::persist::KVStore
184184
WriteFailed,
185185
/// We failed to access the given `storage_dir_path`.
186186
StoragePathAccessFailed,
187187
/// We failed to setup our [`KVStore`].
188188
///
189-
/// [`KVStore`]: lightning::util::persist::KVStoreSync
189+
/// [`KVStore`]: lightning::util::persist::KVStore
190190
KVStoreSetupFailed,
191191
/// We failed to setup the onchain wallet.
192192
WalletSetupFailed,
@@ -697,11 +697,12 @@ impl NodeBuilder {
697697
/// [`FilesystemStoreV2`]: lightning_persister::fs_store::v2::FilesystemStoreV2
698698
pub fn build_with_fs_store(&self, node_entropy: NodeEntropy) -> Result<Node, BuildError> {
699699
let logger = setup_logger(&self.log_writer_config, &self.config)?;
700+
let runtime = self.setup_runtime(&logger)?;
700701
let mut storage_dir_path: PathBuf = self.config.storage_dir_path.clone().into();
701702
storage_dir_path.push("fs_store");
702703

703-
let kv_store = open_or_migrate_fs_store(storage_dir_path)?;
704-
self.build_with_store_and_logger(node_entropy, kv_store, logger)
704+
let kv_store = runtime.block_on(open_or_migrate_fs_store(storage_dir_path))?;
705+
self.build_with_store_runtime_and_logger(node_entropy, kv_store, runtime, logger)
705706
}
706707

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

827828
/// Builds a [`Node`] instance according to the options previously configured.
828-
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
829+
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
829830
&self, node_entropy: NodeEntropy, kv_store: S,
830831
) -> Result<Node, BuildError> {
831832
let logger = setup_logger(&self.log_writer_config, &self.config)?;
@@ -844,14 +845,14 @@ impl NodeBuilder {
844845
}
845846
}
846847

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

854-
fn build_with_store_runtime_and_logger<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
855+
fn build_with_store_runtime_and_logger<S: KVStore + Send + Sync + 'static>(
855856
&self, node_entropy: NodeEntropy, kv_store: S, runtime: Arc<Runtime>, logger: Arc<Logger>,
856857
) -> Result<Node, BuildError> {
857858
let seed_bytes = node_entropy.to_seed_bytes();
@@ -1345,7 +1346,7 @@ impl ArcedNodeBuilder {
13451346
/// Builds a [`Node`] instance according to the options previously configured.
13461347
// Note that the generics here don't actually work for Uniffi, but we don't currently expose
13471348
// this so its not needed.
1348-
pub fn build_with_store<S: SyncAndAsyncKVStore + Send + Sync + 'static>(
1349+
pub fn build_with_store<S: KVStore + Send + Sync + 'static>(
13491350
&self, node_entropy: Arc<NodeEntropy>, kv_store: S,
13501351
) -> Result<Arc<Node>, BuildError> {
13511352
self.inner.read().expect("lock").build_with_store(*node_entropy, kv_store).map(Arc::new)
@@ -1415,10 +1416,10 @@ fn build_with_store_internal(
14151416

14161417
// Initialize the status fields.
14171418
let node_metrics = match node_metris_res {
1418-
Ok(metrics) => Arc::new(RwLock::new(metrics)),
1419+
Ok(metrics) => Arc::new(PersistedNodeMetrics::new(metrics)),
14191420
Err(e) => {
14201421
if e.kind() == std::io::ErrorKind::NotFound {
1421-
Arc::new(RwLock::new(NodeMetrics::default()))
1422+
Arc::new(PersistedNodeMetrics::new(NodeMetrics::default()))
14221423
} else {
14231424
log_error!(logger, "Failed to read node metrics from store: {}", e);
14241425
return Err(BuildError::ReadFailed);
@@ -1539,12 +1540,16 @@ fn build_with_store_internal(
15391540
let change_descriptor = Bip84(xprv, KeychainKind::Internal);
15401541
let mut wallet_persister =
15411542
KVStoreWalletPersister::new(Arc::clone(&kv_store), Arc::clone(&logger));
1542-
let wallet_opt = BdkWallet::load()
1543-
.descriptor(KeychainKind::External, Some(descriptor.clone()))
1544-
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
1545-
.extract_keys()
1546-
.check_network(config.network)
1547-
.load_wallet(&mut wallet_persister)
1543+
let wallet_opt = runtime
1544+
.block_on(async {
1545+
BdkWallet::load()
1546+
.descriptor(KeychainKind::External, Some(descriptor.clone()))
1547+
.descriptor(KeychainKind::Internal, Some(change_descriptor.clone()))
1548+
.extract_keys()
1549+
.check_network(config.network)
1550+
.load_wallet_async(&mut wallet_persister)
1551+
.await
1552+
})
15481553
.map_err(|e| match e {
15491554
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
15501555
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
@@ -1568,9 +1573,13 @@ fn build_with_store_internal(
15681573
let bdk_wallet = match wallet_opt {
15691574
Some(wallet) => wallet,
15701575
None => {
1571-
let mut wallet = BdkWallet::create(descriptor, change_descriptor)
1572-
.network(config.network)
1573-
.create_wallet(&mut wallet_persister)
1576+
let mut wallet = runtime
1577+
.block_on(async {
1578+
BdkWallet::create(descriptor, change_descriptor)
1579+
.network(config.network)
1580+
.create_wallet_async(&mut wallet_persister)
1581+
.await
1582+
})
15741583
.map_err(|e| {
15751584
log_error!(logger, "Failed to set up wallet: {}", e);
15761585
BuildError::WalletSetupFailed
@@ -1619,6 +1628,7 @@ fn build_with_store_internal(
16191628
Arc::clone(&fee_estimator),
16201629
Arc::clone(&chain_source),
16211630
Arc::clone(&payment_store),
1631+
Arc::clone(&runtime),
16221632
Arc::clone(&config),
16231633
Arc::clone(&logger),
16241634
Arc::clone(&pending_payment_store),

src/chain/bitcoind.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::fee_estimator::{
4242
use crate::io::utils::update_and_persist_node_metrics;
4343
use crate::logger::{log_bytes, log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
4444
use crate::types::{ChainMonitor, ChannelManager, DynStore, Sweeper, Wallet};
45-
use crate::{Error, NodeMetrics};
45+
use crate::{Error, PersistedNodeMetrics};
4646

4747
const CHAIN_POLLING_INTERVAL_SECS: u64 = 2;
4848
const CHAIN_POLLING_TIMEOUT_SECS: u64 = 10;
@@ -55,14 +55,14 @@ pub(super) struct BitcoindChainSource {
5555
kv_store: Arc<DynStore>,
5656
config: Arc<Config>,
5757
logger: Arc<Logger>,
58-
node_metrics: Arc<RwLock<NodeMetrics>>,
58+
node_metrics: Arc<PersistedNodeMetrics>,
5959
}
6060

6161
impl BitcoindChainSource {
6262
pub(crate) fn new_rpc(
6363
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
6464
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
65-
logger: Arc<Logger>, node_metrics: Arc<RwLock<NodeMetrics>>,
65+
logger: Arc<Logger>, node_metrics: Arc<PersistedNodeMetrics>,
6666
) -> Self {
6767
let api_client = Arc::new(BitcoindClient::new_rpc(
6868
rpc_host.clone(),
@@ -89,7 +89,7 @@ impl BitcoindChainSource {
8989
rpc_host: String, rpc_port: u16, rpc_user: String, rpc_password: String,
9090
fee_estimator: Arc<OnchainFeeEstimator>, kv_store: Arc<DynStore>, config: Arc<Config>,
9191
rest_client_config: BitcoindRestClientConfig, logger: Arc<Logger>,
92-
node_metrics: Arc<RwLock<NodeMetrics>>,
92+
node_metrics: Arc<PersistedNodeMetrics>,
9393
) -> Self {
9494
let api_client = Arc::new(BitcoindClient::new_rest(
9595
rest_client_config.rest_host,
@@ -204,6 +204,7 @@ impl BitcoindChainSource {
204204
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
205205
},
206206
)
207+
.await
207208
.unwrap_or_else(|e| {
208209
log_error!(self.logger, "Failed to persist node metrics: {}", e);
209210
});
@@ -451,7 +452,8 @@ impl BitcoindChainSource {
451452
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
452453
m.latest_lightning_wallet_sync_timestamp = unix_time_secs_opt;
453454
m.latest_onchain_wallet_sync_timestamp = unix_time_secs_opt;
454-
})?;
455+
})
456+
.await?;
455457

456458
Ok(())
457459
}
@@ -563,7 +565,8 @@ impl BitcoindChainSource {
563565
SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
564566
update_and_persist_node_metrics(&self.node_metrics, &*self.kv_store, &*self.logger, |m| {
565567
m.latest_fee_rate_cache_update_timestamp = unix_time_secs_opt
566-
})?;
568+
})
569+
.await?;
567570

568571
Ok(())
569572
}

0 commit comments

Comments
 (0)