Skip to content

Commit bd9d4cc

Browse files
Aditya SharmaAditya Sharma
Aditya Sharma
authored and
Aditya Sharma
committed
channelmanager: Create FundRecoverer to take our node in offline mode so that we can just send a BogusChannelReestablish and close all the StubChannelMonitors and sweep the funds from the events.
1 parent 6b9cdb3 commit bd9d4cc

File tree

6 files changed

+887
-36
lines changed

6 files changed

+887
-36
lines changed

lightning/src/chain/chainmonitor.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ pub trait Persist<ChannelSigner: EcdsaChannelSigner> {
165165
fn archive_persisted_channel(&self, channel_funding_outpoint: OutPoint);
166166
}
167167

168-
struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
169-
monitor: ChannelMonitor<ChannelSigner>,
168+
pub(crate) struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
169+
pub(crate) monitor: ChannelMonitor<ChannelSigner>,
170170
/// The full set of pending monitor updates for this Channel.
171171
///
172172
/// Note that this lock must be held from [`ChannelMonitor::update_monitor`] through to
@@ -181,7 +181,7 @@ struct MonitorHolder<ChannelSigner: EcdsaChannelSigner> {
181181
/// could cause users to have a full [`ChannelMonitor`] on disk as well as a
182182
/// [`ChannelMonitorUpdate`] which was already applied. While this isn't an issue for the
183183
/// LDK-provided update-based [`Persist`], it is somewhat surprising for users so we avoid it.
184-
pending_monitor_updates: Mutex<Vec<u64>>,
184+
pub(crate) pending_monitor_updates: Mutex<Vec<u64>>,
185185
}
186186

187187
impl<ChannelSigner: EcdsaChannelSigner> MonitorHolder<ChannelSigner> {
@@ -195,8 +195,8 @@ impl<ChannelSigner: EcdsaChannelSigner> MonitorHolder<ChannelSigner> {
195195
/// Note that this holds a mutex in [`ChainMonitor`] and may block other events until it is
196196
/// released.
197197
pub struct LockedChannelMonitor<'a, ChannelSigner: EcdsaChannelSigner> {
198-
lock: RwLockReadGuard<'a, HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
199-
funding_txo: OutPoint,
198+
pub(crate) lock: RwLockReadGuard<'a, HashMap<OutPoint, MonitorHolder<ChannelSigner>>>,
199+
pub(crate) funding_txo: OutPoint,
200200
}
201201

202202
impl<ChannelSigner: EcdsaChannelSigner> Deref for LockedChannelMonitor<'_, ChannelSigner> {
@@ -750,17 +750,6 @@ where C::Target: chain::Filter,
750750
L::Target: Logger,
751751
P::Target: Persist<ChannelSigner>,
752752
{
753-
fn get_stub_cids_with_counterparty(&self, counterparty_node_id: PublicKey) -> Vec<ChannelId> {
754-
let stub_monitors = self.stub_monitors.read().unwrap();
755-
let mut stubs = vec![];
756-
for (_, mon) in stub_monitors.iter() {
757-
if mon.get_counterparty_node_id() == Some(counterparty_node_id) {
758-
stubs.push(mon.channel_id());
759-
}
760-
}
761-
stubs
762-
}
763-
764753
fn watch_channel(&self, funding_outpoint: OutPoint, monitor: ChannelMonitor<ChannelSigner>) -> Result<ChannelMonitorUpdateStatus, ()> {
765754
let logger = WithChannelMonitor::from(&self.logger, &monitor, None);
766755
let mut monitors = self.monitors.write().unwrap();

lightning/src/chain/channelmonitor.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
18841884
}
18851885
}
18861886

1887+
pub fn update_latest_state_from_new_stubmonitor(&self, stub: &StubChannel) {
1888+
self.inner.lock().unwrap().update_latest_state_from_new_stubmonitor(stub);
1889+
}
1890+
18871891
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
18881892
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
18891893
pub fn get_and_clear_pending_monitor_events(&self) -> Vec<MonitorEvent> {
@@ -3727,13 +3731,14 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
37273731
self.current_holder_commitment_number
37283732
}
37293733

3730-
/// Updates the [`StubChannelMonitor`] when we receive a new more recent
3731-
/// peer storage from our peer. This souldn't be called through [`ChannelMonitor`].
3732-
fn update_latest_state_from_new_stubchannelmonitor(&mut self, stub: &StubChannelMonitor<Signer>) {
3733-
let inner = stub.inner.lock().unwrap();
3734-
self.commitment_secrets = inner.commitment_secrets.clone();
3735-
self.counterparty_claimable_outpoints = inner.counterparty_claimable_outpoints.clone();
3736-
self.their_cur_per_commitment_points = inner.their_cur_per_commitment_points.clone();
3734+
/// Updates the [`ChannelMonitor`] when we receive a new more recent
3735+
/// peer storage from our peer.
3736+
fn update_latest_state_from_new_stubmonitor(&mut self, stub: &StubChannel) {
3737+
let mut latest_state = new_hash_map();
3738+
latest_state.insert(stub.latest_state.unwrap(), Vec::new());
3739+
self.commitment_secrets = stub.commitment_secrets.clone();
3740+
self.counterparty_claimable_outpoints = latest_state;
3741+
self.their_cur_per_commitment_points = stub.their_cur_per_commitment_points.clone();
37373742
}
37383743

37393744
/// Attempts to claim a counterparty commitment transaction's outputs using the revocation key and

lightning/src/chain/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,6 @@ pub trait Watch<ChannelSigner: EcdsaChannelSigner> {
305305
/// For details on asynchronous [`ChannelMonitor`] updating and returning
306306
/// [`MonitorEvent::Completed`] here, see [`ChannelMonitorUpdateStatus::InProgress`].
307307
fn release_pending_monitor_events(&self) -> Vec<(OutPoint, ChannelId, Vec<MonitorEvent>, Option<PublicKey>)>;
308-
309-
/// Retrieves a list of channel IDs for [`StubChannelMonitor`] associated with a specific counterparty node ID.
310-
///
311-
/// This function searches through the collection of [`StubChannelMonitor`] and collects the channel IDs
312-
/// of those monitors that have the specified counterparty node ID.
313-
///
314-
/// This is used by [`FundRecoverer`] to fetch all the [`ChannelId`] with a peer that needs recovery so that we can send them
315-
/// `BogusChannelReestablish`.
316-
fn get_stub_cids_with_counterparty(&self, counterparty_node_id: PublicKey) -> Vec<ChannelId>;
317308
}
318309

319310
/// The `Filter` trait defines behavior for indicating chain activity of interest pertaining to

0 commit comments

Comments
 (0)