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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub use crate::ldkstorage::{
ACTIVE_NODE_ID_KEY, CHANNEL_CLOSURE_BUMP_PREFIX, CHANNEL_CLOSURE_PREFIX, CHANNEL_MANAGER_KEY,
MONITORS_PREFIX_KEY,
};
use crate::lsp::lndchannel::fetch_lnd_channels_snapshot;
use crate::lsp::lndchannel::{
fetch_lnd_channels, fetch_lnd_channels_snapshot, LndChannelsSnapshot,
};
use crate::messagehandler::CommonLnEventCallback;
use crate::nodemanager::NodeManager;
use crate::nodemanager::{ChannelClosure, MutinyBip21RawMaterials};
Expand Down Expand Up @@ -835,11 +837,12 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
return;
};

let first_lnd_snapshot =
match fetch_lnd_channels_snapshot(&Client::new(), lsp_url, &node_id, &logger).await {
Ok(snapshot) => {
log_debug!(logger, "First fetched lnd snapshot: {:?}", snapshot);
snapshot
let (lnd_channels, first_lnd_snapshot) =
match fetch_lnd_channels(&Client::new(), lsp_url, &node_id, &logger).await {
Ok(lnd_channels) => {
let lnd_snapshot: LndChannelsSnapshot = lnd_channels.clone().into();
log_debug!(logger, "First fetched lnd snapshot: {:?}", lnd_snapshot);
(lnd_channels, lnd_snapshot)
}
Err(e) => {
log_error!(logger, "First lnd snapshot fetch failed: {e}");
Expand All @@ -851,7 +854,7 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
let only_device_lock_vss_pending =
pending.len() == 1 && pending.iter().any(|(key, _)| key == DEVICE_LOCK_KEY);
let can_update_snapshot = (pending.is_empty() || only_device_lock_vss_pending)
&& CONNECTED_PEER_MANAGER.is_any_connected();
&& CONNECTED_PEER_MANAGER.validate_peer_connections(&lnd_channels);
Comment thread
Flouse marked this conversation as resolved.
if can_update_snapshot {
let second_lnd_snapshot =
match fetch_lnd_channels_snapshot(&Client::new(), lsp_url, &node_id, &logger).await
Expand Down
1 change: 1 addition & 0 deletions mutiny-core/src/lsp/lndchannel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct ChannelConstraints {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LndChannel {
pub active: bool,
pub local_pubkey: String,
pub remote_pubkey: String,
pub channel_point: String,
pub chan_id: String,
Expand Down
45 changes: 41 additions & 4 deletions mutiny-core/src/peermanager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::keymanager::PhantomKeysManager;
use crate::lsp::lndchannel::LndChannel;
use crate::messagehandler::CommonLnEvent;
use crate::messagehandler::MutinyMessageHandler;
#[cfg(target_arch = "wasm32")]
Expand All @@ -24,7 +25,8 @@ use lightning::routing::gossip::NodeId;
use lightning::util::logger::Logger;
use lightning::{ln::msgs::SocketAddress, log_warn};
use lightning::{log_debug, log_error};
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use utils::Mutex;
Expand Down Expand Up @@ -660,8 +662,43 @@ impl ConnectedPeerManager {
}
}

pub fn is_any_connected(&self) -> bool {
let lock = self.peers.lock().unwrap();
!lock.is_empty()
pub fn validate_peer_connections(&self, channels: &[LndChannel]) -> bool {
let (peers_from_lnd, valid) =
Comment thread
Flouse marked this conversation as resolved.
Outdated
channels
.iter()
.fold(
(HashSet::new(), true),
|(mut s, valid), c| match PublicKey::from_str(&c.local_pubkey) {
Ok(k) => {
s.insert(k);
(s, valid)
}
Err(e) => {
if let Some(l) = &*self.logger.lock().unwrap() {
log_warn!(l, "Invalid local_pubkey in {}: {}", c.chan_id, e);
}
(s, false)
}
},
);
if !valid {
return false;
}

let peers_in_manager = {
let peers = self.peers.lock().unwrap();
peers.keys().cloned().collect::<HashSet<_>>()
};

let is_match = peers_from_lnd.is_subset(&peers_in_manager);
if !is_match {
if let Some(l) = &*self.logger.lock().unwrap() {
peers_from_lnd
.difference(&peers_in_manager)
.for_each(|pk| log_warn!(l, "Missing peer: {}", pk));
}
}

is_match
}
}
2 changes: 1 addition & 1 deletion mutiny-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["per-package-target"]

[package]
name = "mutiny-wasm"
version = "1.14.5"
version = "1.14.6"
edition = "2021"
authors = ["utxostack"]
forced-target = "wasm32-unknown-unknown"
Expand Down
Loading