@@ -1193,15 +1193,15 @@ where
11931193 /// `PersistenceNotifierGuard::notify_on_drop(..)` and pass the lock to it, to ensure the
11941194 /// Notifier the lock contains sends out a notification when the lock is released.
11951195 total_consistency_lock: RwLock<()>,
1196- /// Tracks the progress of channels going through batch v1 channel establishment by whether
1197- /// funding_signed was received and the monitor has been persisted.
1196+ /// Tracks the progress of channels going through batch funding by whether funding_signed was
1197+ /// received and the monitor has been persisted.
11981198 ///
11991199 /// This information does not need to be persisted as funding nodes can forget
12001200 /// unfunded channels upon disconnection.
1201- v1_funding_batch_states : FairRwLock<HashMap<Txid, Mutex<HashMap<([u8;32], PublicKey), bool>>>>,
1201+ funding_batch_states : FairRwLock<HashMap<Txid, Mutex<HashMap<([u8;32], PublicKey), bool>>>>,
12021202 /// Remaining channels in a funding batch need to be closed when one channel closes.
12031203 /// These batches are maintained here to be periodically processed to simplify locking behavior.
1204- v1_funding_batches_to_be_closed : Mutex<Vec<Txid>>,
1204+ funding_batches_to_be_closed : Mutex<Vec<Txid>>,
12051205
12061206 background_events_processed_since_startup: AtomicBool,
12071207
@@ -1813,10 +1813,10 @@ macro_rules! update_maps_on_chan_removal {
18131813 short_to_chan_info.remove(&$channel_context.outbound_scid_alias());
18141814 // If the channel was part of a batch funding transaction, all channels in that
18151815 // batch are affected.
1816- let v1_funding_batch_states = $self.v1_funding_batch_states .read().unwrap();
1816+ let funding_batch_states = $self.funding_batch_states .read().unwrap();
18171817 $channel_context.unbroadcasted_funding_txid().map(|txid| {
1818- if v1_funding_batch_states .contains_key(&txid) {
1819- $self.v1_funding_batches_to_be_closed .lock().unwrap().push(txid);
1818+ if funding_batch_states .contains_key(&txid) {
1819+ $self.funding_batches_to_be_closed .lock().unwrap().push(txid);
18201820 }
18211821 })
18221822 }}
@@ -1967,9 +1967,9 @@ macro_rules! handle_monitor_update_completion {
19671967 // should be updated as we have received funding_signed and persisted the monitor.
19681968 let mut completed_batch = None;
19691969 {
1970- let v1_funding_batch_states = $self.v1_funding_batch_states .read().unwrap();
1970+ let funding_batch_states = $self.funding_batch_states .read().unwrap();
19711971 let batch_state_key_value = $chan.context.unbroadcasted_funding_txid()
1972- .and_then(|txid| v1_funding_batch_states .get_key_value(&txid));
1972+ .and_then(|txid| funding_batch_states .get_key_value(&txid));
19731973 if let Some((txid, batch_state)) = batch_state_key_value {
19741974 let mut batch_state = batch_state.lock().unwrap();
19751975 batch_state.insert(
@@ -2019,7 +2019,7 @@ macro_rules! handle_monitor_update_completion {
20192019 // When all channels in a batched funding transaction have become ready, it is not necessary
20202020 // to track the progress of the batch anymore and the state of the channels can be updated.
20212021 if let Some(txid) = completed_batch {
2022- let other_channel_ids = $self.v1_funding_batch_states .write().unwrap()
2022+ let other_channel_ids = $self.funding_batch_states .write().unwrap()
20232023 .remove(&txid)
20242024 .map(|batch_state| batch_state.into_inner().unwrap().into_iter().map(|(k, _)| k))
20252025 .into_iter().flatten()
@@ -2254,8 +2254,8 @@ where
22542254 total_consistency_lock: RwLock::new(()),
22552255 background_events_processed_since_startup: AtomicBool::new(false),
22562256 persistence_notifier: Notifier::new(),
2257- v1_funding_batch_states : FairRwLock::new(HashMap::new()),
2258- v1_funding_batches_to_be_closed : Mutex::new(Vec::new()),
2257+ funding_batch_states : FairRwLock::new(HashMap::new()),
2258+ funding_batches_to_be_closed : Mutex::new(Vec::new()),
22592259
22602260 entropy_source,
22612261 node_signer,
@@ -3659,7 +3659,7 @@ where
36593659 }
36603660
36613661 let is_batch_funding = temporary_channels.len() > 1;
3662- let v1_funding_batch_state = RefCell::new(HashMap::new());
3662+ let funding_batch_state = RefCell::new(HashMap::new());
36633663 for (temporary_channel_id, counterparty_node_id) in temporary_channels {
36643664 result = result.and_then(|_| self.funding_transaction_generated_intern(
36653665 temporary_channel_id,
@@ -3684,7 +3684,7 @@ where
36843684 });
36853685 }
36863686 let outpoint = OutPoint { txid: tx.txid(), index: output_index.unwrap() };
3687- v1_funding_batch_state .borrow_mut().insert((outpoint.to_channel_id(), (*counterparty_node_id).clone()), false);
3687+ funding_batch_state .borrow_mut().insert((outpoint.to_channel_id(), (*counterparty_node_id).clone()), false);
36883688 Ok(outpoint)
36893689 })
36903690 );
@@ -3702,7 +3702,7 @@ where
37023702 self.issue_channel_close_events(&chan.context, ClosureReason::ProcessingError { err: e.clone() });
37033703 });
37043704 }
3705- for (channel_id, counterparty_node_id) in v1_funding_batch_state .borrow().keys() {
3705+ for (channel_id, counterparty_node_id) in funding_batch_state .borrow().keys() {
37063706 per_peer_state.get(counterparty_node_id)
37073707 .map(|peer_state_mutex| peer_state_mutex.lock().unwrap())
37083708 .and_then(|mut peer_state| peer_state.channel_by_id.remove(channel_id))
@@ -3713,9 +3713,9 @@ where
37133713 }
37143714 } else if is_batch_funding {
37153715 // Initialize the state of the batch.
3716- self.v1_funding_batch_states .write().unwrap().insert(
3716+ self.funding_batch_states .write().unwrap().insert(
37173717 funding_transaction.txid(),
3718- Mutex::new(v1_funding_batch_state .into_inner()),
3718+ Mutex::new(funding_batch_state .into_inner()),
37193719 );
37203720 }
37213721 result
@@ -4779,9 +4779,9 @@ where
47794779 // Close remaining channels in funding batches when one channel closes.
47804780 let mut affected_channels = Vec::new();
47814781 {
4782- let mut v1_funding_batch_states = self.v1_funding_batch_states .write().unwrap();
4783- for txid in self.v1_funding_batches_to_be_closed .lock().unwrap().drain(..) {
4784- affected_channels.extend(v1_funding_batch_states
4782+ let mut funding_batch_states = self.funding_batch_states .write().unwrap();
4783+ for txid in self.funding_batches_to_be_closed .lock().unwrap().drain(..) {
4784+ affected_channels.extend(funding_batch_states
47854785 .remove(&txid)
47864786 .map(|state| state.into_inner().unwrap().into_iter().map(|(k, _)| k))
47874787 .into_iter().flatten()
@@ -5845,7 +5845,7 @@ where
58455845 match peer_state.channel_by_id.entry(msg.channel_id) {
58465846 hash_map::Entry::Occupied(mut chan) => {
58475847 let is_batch_funding = chan.get().context.unbroadcasted_funding_txid()
5848- .map(|txid| self.v1_funding_batch_states .read().unwrap().contains_key(&txid))
5848+ .map(|txid| self.funding_batch_states .read().unwrap().contains_key(&txid))
58495849 .unwrap_or(false);
58505850 let monitor = try_chan_entry!(self,
58515851 chan.get_mut().funding_signed(&msg, best_block, &self.signer_provider, is_batch_funding, &self.logger), chan);
@@ -7547,20 +7547,24 @@ where
75477547 let peer_state = &mut *peer_state_lock;
75487548
75497549 peer_state.channel_by_id.retain(|_, chan| {
7550- if !chan.context.is_funding_initiated() {
7550+ if !chan.context.is_funding_broadcast() {
7551+ update_maps_on_chan_removal!(self, &chan.context);
7552+ self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
75517553 // It is possible to have persisted the monitor upon funding_signed
75527554 // but not have broadcast the transaction, especially for batch funding.
75537555 // The monitor should be moved to the correct state.
75547556 self.finish_force_close_channel(chan.context.force_shutdown(false));
7557+ false
75557558 } else {
75567559 chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
7560+ if chan.is_shutdown() {
7561+ update_maps_on_chan_removal!(self, &chan.context);
7562+ self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
7563+ false
7564+ } else {
7565+ true
7566+ }
75577567 }
7558- if chan.is_shutdown() {
7559- update_maps_on_chan_removal!(self, &chan.context);
7560- self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
7561- return false;
7562- }
7563- true
75647568 });
75657569 peer_state.inbound_v1_channel_by_id.retain(|_, chan| {
75667570 update_maps_on_chan_removal!(self, &chan.context);
@@ -8365,7 +8369,7 @@ where
83658369 }
83668370 number_of_channels += peer_state.channel_by_id.len();
83678371 for (_, channel) in peer_state.channel_by_id.iter() {
8368- if !channel.context.is_funding_initiated () {
8372+ if !channel.context.is_funding_broadcast () {
83698373 unfunded_channels += 1;
83708374 }
83718375 }
@@ -8377,7 +8381,7 @@ where
83778381 let mut peer_state_lock = peer_state_mutex.lock().unwrap();
83788382 let peer_state = &mut *peer_state_lock;
83798383 for (_, channel) in peer_state.channel_by_id.iter() {
8380- if channel.context.is_funding_initiated () {
8384+ if channel.context.is_funding_broadcast () {
83818385 channel.write(writer)?;
83828386 }
83838387 }
@@ -8824,7 +8828,7 @@ where
88248828 if let Some(short_channel_id) = channel.context.get_short_channel_id() {
88258829 short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id()));
88268830 }
8827- if channel.context.is_funding_initiated () {
8831+ if channel.context.is_funding_broadcast () {
88288832 id_to_peer.insert(channel.context.channel_id(), channel.context.get_counterparty_node_id());
88298833 }
88308834 match peer_channels.entry(channel.context.get_counterparty_node_id()) {
@@ -9521,8 +9525,8 @@ where
95219525 total_consistency_lock: RwLock::new(()),
95229526 background_events_processed_since_startup: AtomicBool::new(false),
95239527 persistence_notifier: Notifier::new(),
9524- v1_funding_batch_states : FairRwLock::new(HashMap::new()),
9525- v1_funding_batches_to_be_closed : Mutex::new(Vec::new()),
9528+ funding_batch_states : FairRwLock::new(HashMap::new()),
9529+ funding_batches_to_be_closed : Mutex::new(Vec::new()),
95269530
95279531 entropy_source: args.entropy_source,
95289532 node_signer: args.node_signer,
0 commit comments