@@ -1198,15 +1198,15 @@ where
1198
1198
/// `PersistenceNotifierGuard::notify_on_drop(..)` and pass the lock to it, to ensure the
1199
1199
/// Notifier the lock contains sends out a notification when the lock is released.
1200
1200
total_consistency_lock: RwLock<()>,
1201
- /// Tracks the progress of channels going through batch v1 channel establishment by whether
1202
- /// funding_signed was received and the monitor has been persisted.
1201
+ /// Tracks the progress of channels going through batch funding by whether funding_signed was
1202
+ /// received and the monitor has been persisted.
1203
1203
///
1204
1204
/// This information does not need to be persisted as funding nodes can forget
1205
1205
/// unfunded channels upon disconnection.
1206
- v1_funding_batch_states : FairRwLock<HashMap<Txid, Mutex<HashMap<([u8;32], PublicKey), bool>>>>,
1206
+ funding_batch_states : FairRwLock<HashMap<Txid, Mutex<HashMap<([u8;32], PublicKey), bool>>>>,
1207
1207
/// Remaining channels in a funding batch need to be closed when one channel closes.
1208
1208
/// These batches are maintained here to be periodically processed to simplify locking behavior.
1209
- v1_funding_batches_to_be_closed : Mutex<Vec<Txid>>,
1209
+ funding_batches_to_be_closed : Mutex<Vec<Txid>>,
1210
1210
1211
1211
background_events_processed_since_startup: AtomicBool,
1212
1212
@@ -1818,10 +1818,10 @@ macro_rules! update_maps_on_chan_removal {
1818
1818
short_to_chan_info.remove(&$channel_context.outbound_scid_alias());
1819
1819
// If the channel was part of a batch funding transaction, all channels in that
1820
1820
// batch are affected.
1821
- let v1_funding_batch_states = $self.v1_funding_batch_states .read().unwrap();
1821
+ let funding_batch_states = $self.funding_batch_states .read().unwrap();
1822
1822
$channel_context.unbroadcasted_funding_txid().map(|txid| {
1823
- if v1_funding_batch_states .contains_key(&txid) {
1824
- $self.v1_funding_batches_to_be_closed .lock().unwrap().push(txid);
1823
+ if funding_batch_states .contains_key(&txid) {
1824
+ $self.funding_batches_to_be_closed .lock().unwrap().push(txid);
1825
1825
}
1826
1826
})
1827
1827
}}
@@ -1972,9 +1972,9 @@ macro_rules! handle_monitor_update_completion {
1972
1972
// should be updated as we have received funding_signed and persisted the monitor.
1973
1973
let mut completed_batch = None;
1974
1974
{
1975
- let v1_funding_batch_states = $self.v1_funding_batch_states .read().unwrap();
1975
+ let funding_batch_states = $self.funding_batch_states .read().unwrap();
1976
1976
let batch_state_key_value = $chan.context.unbroadcasted_funding_txid()
1977
- .and_then(|txid| v1_funding_batch_states .get_key_value(&txid));
1977
+ .and_then(|txid| funding_batch_states .get_key_value(&txid));
1978
1978
if let Some((txid, batch_state)) = batch_state_key_value {
1979
1979
let mut batch_state = batch_state.lock().unwrap();
1980
1980
batch_state.insert(
@@ -2024,7 +2024,7 @@ macro_rules! handle_monitor_update_completion {
2024
2024
// When all channels in a batched funding transaction have become ready, it is not necessary
2025
2025
// to track the progress of the batch anymore and the state of the channels can be updated.
2026
2026
if let Some(txid) = completed_batch {
2027
- let other_channel_ids = $self.v1_funding_batch_states .write().unwrap()
2027
+ let other_channel_ids = $self.funding_batch_states .write().unwrap()
2028
2028
.remove(&txid)
2029
2029
.map(|batch_state| batch_state.into_inner().unwrap().into_iter().map(|(k, _)| k))
2030
2030
.into_iter().flatten()
@@ -2259,8 +2259,8 @@ where
2259
2259
total_consistency_lock: RwLock::new(()),
2260
2260
background_events_processed_since_startup: AtomicBool::new(false),
2261
2261
persistence_notifier: Notifier::new(),
2262
- v1_funding_batch_states : FairRwLock::new(HashMap::new()),
2263
- v1_funding_batches_to_be_closed : Mutex::new(Vec::new()),
2262
+ funding_batch_states : FairRwLock::new(HashMap::new()),
2263
+ funding_batches_to_be_closed : Mutex::new(Vec::new()),
2264
2264
2265
2265
entropy_source,
2266
2266
node_signer,
@@ -3664,7 +3664,7 @@ where
3664
3664
}
3665
3665
3666
3666
let is_batch_funding = temporary_channels.len() > 1;
3667
- let v1_funding_batch_state = RefCell::new(HashMap::new());
3667
+ let funding_batch_state = RefCell::new(HashMap::new());
3668
3668
for (temporary_channel_id, counterparty_node_id) in temporary_channels {
3669
3669
result = result.and_then(|_| self.funding_transaction_generated_intern(
3670
3670
temporary_channel_id,
@@ -3689,7 +3689,7 @@ where
3689
3689
});
3690
3690
}
3691
3691
let outpoint = OutPoint { txid: tx.txid(), index: output_index.unwrap() };
3692
- v1_funding_batch_state .borrow_mut().insert((outpoint.to_channel_id(), (*counterparty_node_id).clone()), false);
3692
+ funding_batch_state .borrow_mut().insert((outpoint.to_channel_id(), (*counterparty_node_id).clone()), false);
3693
3693
Ok(outpoint)
3694
3694
})
3695
3695
);
@@ -3707,7 +3707,7 @@ where
3707
3707
self.issue_channel_close_events(&chan.context, ClosureReason::ProcessingError { err: e.clone() });
3708
3708
});
3709
3709
}
3710
- for (channel_id, counterparty_node_id) in v1_funding_batch_state .borrow().keys() {
3710
+ for (channel_id, counterparty_node_id) in funding_batch_state .borrow().keys() {
3711
3711
per_peer_state.get(counterparty_node_id)
3712
3712
.map(|peer_state_mutex| peer_state_mutex.lock().unwrap())
3713
3713
.and_then(|mut peer_state| peer_state.channel_by_id.remove(channel_id))
@@ -3718,9 +3718,9 @@ where
3718
3718
}
3719
3719
} else if is_batch_funding {
3720
3720
// Initialize the state of the batch.
3721
- self.v1_funding_batch_states .write().unwrap().insert(
3721
+ self.funding_batch_states .write().unwrap().insert(
3722
3722
funding_transaction.txid(),
3723
- Mutex::new(v1_funding_batch_state .into_inner()),
3723
+ Mutex::new(funding_batch_state .into_inner()),
3724
3724
);
3725
3725
}
3726
3726
result
@@ -4784,9 +4784,9 @@ where
4784
4784
// Close remaining channels in funding batches when one channel closes.
4785
4785
let mut affected_channels = Vec::new();
4786
4786
{
4787
- let mut v1_funding_batch_states = self.v1_funding_batch_states .write().unwrap();
4788
- for txid in self.v1_funding_batches_to_be_closed .lock().unwrap().drain(..) {
4789
- affected_channels.extend(v1_funding_batch_states
4787
+ let mut funding_batch_states = self.funding_batch_states .write().unwrap();
4788
+ for txid in self.funding_batches_to_be_closed .lock().unwrap().drain(..) {
4789
+ affected_channels.extend(funding_batch_states
4790
4790
.remove(&txid)
4791
4791
.map(|state| state.into_inner().unwrap().into_iter().map(|(k, _)| k))
4792
4792
.into_iter().flatten()
@@ -5850,7 +5850,7 @@ where
5850
5850
match peer_state.channel_by_id.entry(msg.channel_id) {
5851
5851
hash_map::Entry::Occupied(mut chan) => {
5852
5852
let is_batch_funding = chan.get().context.unbroadcasted_funding_txid()
5853
- .map(|txid| self.v1_funding_batch_states .read().unwrap().contains_key(&txid))
5853
+ .map(|txid| self.funding_batch_states .read().unwrap().contains_key(&txid))
5854
5854
.unwrap_or(false);
5855
5855
let monitor = try_chan_entry!(self,
5856
5856
chan.get_mut().funding_signed(&msg, best_block, &self.signer_provider, is_batch_funding, &self.logger), chan);
@@ -7552,20 +7552,24 @@ where
7552
7552
let peer_state = &mut *peer_state_lock;
7553
7553
7554
7554
peer_state.channel_by_id.retain(|_, chan| {
7555
- if !chan.context.is_funding_initiated() {
7555
+ if !chan.context.is_funding_broadcast() {
7556
+ update_maps_on_chan_removal!(self, &chan.context);
7557
+ self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
7556
7558
// It is possible to have persisted the monitor upon funding_signed
7557
7559
// but not have broadcast the transaction, especially for batch funding.
7558
7560
// The monitor should be moved to the correct state.
7559
7561
self.finish_force_close_channel(chan.context.force_shutdown(false));
7562
+ false
7560
7563
} else {
7561
7564
chan.remove_uncommitted_htlcs_and_mark_paused(&self.logger);
7565
+ if chan.is_shutdown() {
7566
+ update_maps_on_chan_removal!(self, &chan.context);
7567
+ self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
7568
+ false
7569
+ } else {
7570
+ true
7571
+ }
7562
7572
}
7563
- if chan.is_shutdown() {
7564
- update_maps_on_chan_removal!(self, &chan.context);
7565
- self.issue_channel_close_events(&chan.context, ClosureReason::DisconnectedPeer);
7566
- return false;
7567
- }
7568
- true
7569
7573
});
7570
7574
peer_state.inbound_v1_channel_by_id.retain(|_, chan| {
7571
7575
update_maps_on_chan_removal!(self, &chan.context);
@@ -8370,7 +8374,7 @@ where
8370
8374
}
8371
8375
number_of_channels += peer_state.channel_by_id.len();
8372
8376
for (_, channel) in peer_state.channel_by_id.iter() {
8373
- if !channel.context.is_funding_initiated () {
8377
+ if !channel.context.is_funding_broadcast () {
8374
8378
unfunded_channels += 1;
8375
8379
}
8376
8380
}
@@ -8382,7 +8386,7 @@ where
8382
8386
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
8383
8387
let peer_state = &mut *peer_state_lock;
8384
8388
for (_, channel) in peer_state.channel_by_id.iter() {
8385
- if channel.context.is_funding_initiated () {
8389
+ if channel.context.is_funding_broadcast () {
8386
8390
channel.write(writer)?;
8387
8391
}
8388
8392
}
@@ -8829,7 +8833,7 @@ where
8829
8833
if let Some(short_channel_id) = channel.context.get_short_channel_id() {
8830
8834
short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id()));
8831
8835
}
8832
- if channel.context.is_funding_initiated () {
8836
+ if channel.context.is_funding_broadcast () {
8833
8837
id_to_peer.insert(channel.context.channel_id(), channel.context.get_counterparty_node_id());
8834
8838
}
8835
8839
match peer_channels.entry(channel.context.get_counterparty_node_id()) {
@@ -9526,8 +9530,8 @@ where
9526
9530
total_consistency_lock: RwLock::new(()),
9527
9531
background_events_processed_since_startup: AtomicBool::new(false),
9528
9532
persistence_notifier: Notifier::new(),
9529
- v1_funding_batch_states : FairRwLock::new(HashMap::new()),
9530
- v1_funding_batches_to_be_closed : Mutex::new(Vec::new()),
9533
+ funding_batch_states : FairRwLock::new(HashMap::new()),
9534
+ funding_batches_to_be_closed : Mutex::new(Vec::new()),
9531
9535
9532
9536
entropy_source: args.entropy_source,
9533
9537
node_signer: args.node_signer,
0 commit comments