Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n 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;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
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
11 changes: 5 additions & 6 deletions benches/payments.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,12 +35,10 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

let payment_id = node_a.spontaneous_payment().send_with_preimage(
amount_msat,
node_b.node_id(),
preimage,
None,
);
let payment_id = node_a
.spontaneous_payment()
.send_with_preimage(amount_msat, node_b.node_id(), preimage, None)
.await;

match payment_id {
Ok(payment_id) => {
Expand DownExpand Up@@ -110,6 +108,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
PaymentPreimage(preimage_bytes),
None,
)
.await
.ok()
.unwrap();

Expand Down
66 changes: 33 additions & 33 deletions bindings/ldk_node.udl
Original file line numberDiff line numberDiff line change
Expand Up@@ -164,28 +164,28 @@ interface Node {
OnchainPayment onchain_payment();
UnifiedPayment unified_payment();
LSPS1Liquidity lsps1_liquidity();
[Throws=NodeError]
[Throws=NodeError, Async]
void connect(PublicKey node_id, SocketAddress address, boolean persist);
[Throws=NodeError]
[Throws=NodeError, Async]
void disconnect(PublicKey node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
[Throws=NodeError]
[Throws=NodeError, Async]
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void force_close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, string? reason);
[Throws=NodeError]
void update_channel_config([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
PaymentDetails? payment([ByRef]PaymentId payment_id);
[Throws=NodeError]
[Throws=NodeError, Async]
void remove_payment([ByRef]PaymentId payment_id);
BalanceDetails list_balances();
sequence<PaymentDetails> list_payments();
Expand All@@ -194,7 +194,7 @@ interface Node {
NetworkGraph network_graph();
string sign_message([ByRef]sequence<u8> msg);
boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
[Throws=NodeError]
[Async, Throws=NodeError]
bytes export_pathfinding_scores();
};

Expand All@@ -205,48 +205,48 @@ interface Bolt11InvoiceDescription {
};

interface Bolt11Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes([ByRef]Bolt11Invoice invoice, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes_using_amount([ByRef]Bolt11Invoice invoice, u64 amount_msat, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void claim_for_hash(PaymentHash payment_hash, u64 claimable_amount_msat, PaymentPreimage preimage);
[Throws=NodeError]
[Throws=NodeError, Async]
void fail_for_hash(PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_via_jit_channel_for_hash(u64 amount_msat, [ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_lsp_fee_limit_msat, PaymentHash payment_hash);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt11Invoice receive_variable_amount_via_jit_channel_for_hash([ByRef]Bolt11InvoiceDescription description, u32 expiry_secs, u64? max_proportional_lsp_fee_limit_ppm_msat, PaymentHash payment_hash);
};

interface Bolt12Payment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send([ByRef]Offer offer, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_using_amount([ByRef]Offer offer, u64 amount_msat, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive(u64 amount_msat, [ByRef]string description, u32? expiry_secs, u64? quantity);
[Throws=NodeError]
Offer receive_variable_amount([ByRef]string description, u32? expiry_secs);
[Throws=NodeError]
[Throws=NodeError, Async]
Bolt12Invoice request_refund_payment([ByRef]Refund refund);
[Throws=NodeError]
[Throws=NodeError, Async]
Refund initiate_refund(u64 amount_msat, u32 expiry_secs, u64? quantity, string? payer_note, RouteParametersConfig? route_parameters);
[Throws=NodeError]
Offer receive_async();
Expand All@@ -257,24 +257,24 @@ interface Bolt12Payment {
};

interface SpontaneousPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_custom_tlvs(u64 amount_msat, PublicKey node_id, RouteParametersConfig? route_parameters, sequence<CustomTlvRecord> custom_tlvs);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage(u64 amount_msat, PublicKey node_id, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
[Throws=NodeError, Async]
PaymentId send_with_preimage_and_custom_tlvs(u64 amount_msat, PublicKey node_id, sequence<CustomTlvRecord> custom_tlvs, PaymentPreimage preimage, RouteParametersConfig? route_parameters);
[Throws=NodeError]
void send_probes(u64 amount_msat, PublicKey node_id);
};

interface OnchainPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
Address new_address();
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_to_address([ByRef]Address address, u64 amount_sats, FeeRate? fee_rate);
[Throws=NodeError]
[Throws=NodeError, Async]
Txid send_all_to_address([ByRef]Address address, boolean retain_reserve, FeeRate? fee_rate);
};

Expand All@@ -289,7 +289,7 @@ interface FeeRate {
};

interface UnifiedPayment {
[Throws=NodeError]
[Throws=NodeError, Async]
string receive(u64 amount_sats, [ByRef]string message, u32 expiry_sec);
[Throws=NodeError, Async]
UnifiedPaymentResult send([ByRef]string uri_str, u64? amount_msat, RouteParametersConfig? route_parameters);
Expand Down
77 changes: 40 additions & 37 deletions src/builder.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,9 +75,9 @@ use crate::peer_store::PeerStore;
use crate::runtime::{Runtime, RuntimeSpawner};
use crate::tx_broadcaster::TransactionBroadcaster;
use crate::types::{
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreWrapper, GossipSync, Graph,
KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager, PendingPaymentStore,
Persister, SyncAndAsyncKVStore,
AsyncPersister, ChainMonitor, ChannelManager, DynStore, DynStoreRef, DynStoreWrapper,
GossipSync, Graph, KeysManager, MessageRouter, OnionMessenger, PaymentStore, PeerManager,
PendingPaymentStore,
};
use crate::wallet::persist::KVStoreWalletPersister;
use crate::wallet::Wallet;
Expand DownExpand Up@@ -169,17 +169,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@@ -655,7 +655,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 DownExpand Up@@ -1020,7 +1020,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().unwrap().build_with_store(*node_entropy, kv_store).map(Arc::new)
Expand DownExpand Up@@ -1193,12 +1193,15 @@ 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(
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),
)
.map_err(|e| match e {
bdk_wallet::LoadWithPersistError::InvalidChangeSet(
bdk_wallet::LoadError::Mismatch(bdk_wallet::LoadMismatch::Network {
Expand All@@ -1222,9 +1225,12 @@ 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(
BdkWallet::create(descriptor, change_descriptor)
.network(config.network)
.create_wallet_async(&mut wallet_persister),
)
.map_err(|e| {
log_error!(logger, "Failed to set up wallet: {}", e);
BuildError::WalletSetupFailed
Expand DownExpand Up@@ -1289,8 +1295,8 @@ fn build_with_store_internal(
));

let peer_storage_key = keys_manager.get_peer_storage_key();
let monitor_reader = Arc::new(AsyncPersister::new(
Arc::clone(&kv_store),
let persister = Arc::new(AsyncPersister::new(
DynStoreRef(Arc::clone(&kv_store)),
RuntimeSpawner::new(Arc::clone(&runtime)),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Expand All@@ -1303,9 +1309,9 @@ fn build_with_store_internal(
// Read ChannelMonitors and the NetworkGraph
let kv_store_ref = Arc::clone(&kv_store);
let logger_ref = Arc::clone(&logger);
let (monitor_read_res, network_graph_res) = runtime.block_on(async move {
let (monitor_read_res, network_graph_res) = runtime.block_on(async {
tokio::join!(
monitor_reader.read_all_channel_monitors_with_updates_parallel(),
persister.read_all_channel_monitors_with_updates_parallel(),
read_network_graph(&*kv_store_ref, logger_ref),
)
});
Expand All@@ -1323,23 +1329,16 @@ fn build_with_store_internal(
},
};

let persister = Arc::new(Persister::new(
Arc::clone(&kv_store),
Arc::clone(&logger),
PERSISTER_MAX_PENDING_UPDATES,
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&tx_broadcaster),
Arc::clone(&fee_estimator),
));
let persister = Arc::try_unwrap(persister)
.unwrap_or_else(|_| panic!("Arc<AsyncPersister> should have no other references"));

// Initialize the ChainMonitor
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new(
let chain_monitor: Arc<ChainMonitor> = Arc::new(chainmonitor::ChainMonitor::new_async_beta(
Some(Arc::clone(&chain_source)),
Arc::clone(&tx_broadcaster),
Arc::clone(&logger),
Arc::clone(&fee_estimator),
Arc::clone(&persister),
persister,
Arc::clone(&keys_manager),
peer_storage_key,
));
Expand DownExpand Up@@ -1565,12 +1564,16 @@ fn build_with_store_internal(
{
let mut locked_node_metrics = node_metrics.write().unwrap();
locked_node_metrics.latest_rgs_snapshot_timestamp = None;
write_node_metrics(&*locked_node_metrics, &*kv_store, Arc::clone(&logger))
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
}
runtime
.block_on(async {
let snapshot = node_metrics.read().unwrap().clone();
write_node_metrics(&snapshot, &*kv_store, Arc::clone(&logger)).await
})
.map_err(|e| {
log_error!(logger, "Failed writing to store: {}", e);
BuildError::WriteFailed
})?;
p2p_source
},
GossipSourceConfig::RapidGossipSync(rgs_server) => {
Expand Down
Loading
Loading