Skip to content

Commit e82cfa7

Browse files
committed
Remove the post_handle_chan_restoration macro
Now that `handle_channel_resumption` can't fail, the error handling in `post_handle_chan_restoration` is now dead code. Removing it makes `post_handle_chan_restoration` only a single block, so here we simply remove the macro and inline the single block into the two places the macro was used.
1 parent f1c6cd8 commit e82cfa7

File tree

1 file changed

+55
-65
lines changed

1 file changed

+55
-65
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,18 +1517,6 @@ macro_rules! emit_channel_ready_event {
15171517
}
15181518
}
15191519

1520-
macro_rules! post_handle_chan_restoration {
1521-
($self: ident, $locked_res: expr, $counterparty_node_id: expr) => { {
1522-
let (htlc_forwards, res) = $locked_res;
1523-
1524-
let _ = handle_error!($self, res, *$counterparty_node_id);
1525-
1526-
if let Some(forwards) = htlc_forwards {
1527-
$self.forward_htlcs(&mut [forwards][..]);
1528-
}
1529-
} }
1530-
}
1531-
15321520
impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F, L>
15331521
where M::Target: chain::Watch<<K::Target as KeysInterface>::Signer>,
15341522
T::Target: BroadcasterInterface,
@@ -4381,69 +4369,66 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
43814369
commitment_update: Option<msgs::CommitmentUpdate>, order: RAACommitmentOrder,
43824370
pending_forwards: Vec<(PendingHTLCInfo, u64)>, funding_broadcastable: Option<Transaction>,
43834371
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>)
4384-
-> (Option<(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)>, Result<(), MsgHandleErrInternal>) {
4372+
-> Option<(u64, OutPoint, Vec<(PendingHTLCInfo, u64)>)> {
43854373
let mut htlc_forwards = None;
43864374

43874375
let counterparty_node_id = channel.get_counterparty_node_id();
4388-
let res = loop {
4389-
if !pending_forwards.is_empty() {
4390-
htlc_forwards = Some((channel.get_short_channel_id().unwrap_or(channel.outbound_scid_alias()),
4391-
channel.get_funding_txo().unwrap(), pending_forwards));
4392-
}
4376+
if !pending_forwards.is_empty() {
4377+
htlc_forwards = Some((channel.get_short_channel_id().unwrap_or(channel.outbound_scid_alias()),
4378+
channel.get_funding_txo().unwrap(), pending_forwards));
4379+
}
43934380

4394-
if let Some(msg) = channel_ready {
4395-
send_channel_ready!(self, pending_msg_events, channel, msg);
4396-
}
4397-
if let Some(msg) = announcement_sigs {
4398-
pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
4381+
if let Some(msg) = channel_ready {
4382+
send_channel_ready!(self, pending_msg_events, channel, msg);
4383+
}
4384+
if let Some(msg) = announcement_sigs {
4385+
pending_msg_events.push(events::MessageSendEvent::SendAnnouncementSignatures {
4386+
node_id: counterparty_node_id,
4387+
msg,
4388+
});
4389+
}
4390+
4391+
emit_channel_ready_event!(self, channel);
4392+
4393+
macro_rules! handle_cs { () => {
4394+
if let Some(update) = commitment_update {
4395+
pending_msg_events.push(events::MessageSendEvent::UpdateHTLCs {
43994396
node_id: counterparty_node_id,
4400-
msg,
4397+
updates: update,
44014398
});
44024399
}
4403-
4404-
emit_channel_ready_event!(self, channel);
4405-
4406-
macro_rules! handle_cs { () => {
4407-
if let Some(update) = commitment_update {
4408-
pending_msg_events.push(events::MessageSendEvent::UpdateHTLCs {
4409-
node_id: counterparty_node_id,
4410-
updates: update,
4411-
});
4412-
}
4413-
} }
4414-
macro_rules! handle_raa { () => {
4415-
if let Some(revoke_and_ack) = raa {
4416-
pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
4417-
node_id: counterparty_node_id,
4418-
msg: revoke_and_ack,
4419-
});
4420-
}
4421-
} }
4422-
match order {
4423-
RAACommitmentOrder::CommitmentFirst => {
4424-
handle_cs!();
4425-
handle_raa!();
4426-
},
4427-
RAACommitmentOrder::RevokeAndACKFirst => {
4428-
handle_raa!();
4429-
handle_cs!();
4430-
},
4400+
} }
4401+
macro_rules! handle_raa { () => {
4402+
if let Some(revoke_and_ack) = raa {
4403+
pending_msg_events.push(events::MessageSendEvent::SendRevokeAndACK {
4404+
node_id: counterparty_node_id,
4405+
msg: revoke_and_ack,
4406+
});
44314407
}
4408+
} }
4409+
match order {
4410+
RAACommitmentOrder::CommitmentFirst => {
4411+
handle_cs!();
4412+
handle_raa!();
4413+
},
4414+
RAACommitmentOrder::RevokeAndACKFirst => {
4415+
handle_raa!();
4416+
handle_cs!();
4417+
},
4418+
}
44324419

4433-
if let Some(tx) = funding_broadcastable {
4434-
log_info!(self.logger, "Broadcasting funding transaction with txid {}", tx.txid());
4435-
self.tx_broadcaster.broadcast_transaction(&tx);
4436-
}
4437-
break Ok(());
4438-
};
4420+
if let Some(tx) = funding_broadcastable {
4421+
log_info!(self.logger, "Broadcasting funding transaction with txid {}", tx.txid());
4422+
self.tx_broadcaster.broadcast_transaction(&tx);
4423+
}
44394424

4440-
(htlc_forwards, res)
4425+
htlc_forwards
44414426
}
44424427

44434428
fn channel_monitor_updated(&self, funding_txo: &OutPoint, highest_applied_update_id: u64) {
44444429
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
44454430

4446-
let chan_restoration_res;
4431+
let htlc_forwards;
44474432
let (mut pending_failures, finalized_claims, counterparty_node_id) = {
44484433
let mut channel_lock = self.channel_state.lock().unwrap();
44494434
let channel_state = &mut *channel_lock;
@@ -4470,14 +4455,16 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
44704455
})
44714456
} else { None }
44724457
} else { None };
4473-
chan_restoration_res = self.handle_channel_resumption(&mut channel_state.pending_msg_events, channel.get_mut(), updates.raa, updates.commitment_update, updates.order, updates.accepted_htlcs, updates.funding_broadcastable, updates.channel_ready, updates.announcement_sigs);
4458+
htlc_forwards = self.handle_channel_resumption(&mut channel_state.pending_msg_events, channel.get_mut(), updates.raa, updates.commitment_update, updates.order, updates.accepted_htlcs, updates.funding_broadcastable, updates.channel_ready, updates.announcement_sigs);
44744459
if let Some(upd) = channel_update {
44754460
channel_state.pending_msg_events.push(upd);
44764461
}
44774462

44784463
(updates.failed_htlcs, updates.finalized_claimed_htlcs, counterparty_node_id)
44794464
};
4480-
post_handle_chan_restoration!(self, chan_restoration_res, &counterparty_node_id);
4465+
if let Some(forwards) = htlc_forwards {
4466+
self.forward_htlcs(&mut [forwards][..]);
4467+
}
44814468
self.finalize_claims(finalized_claims);
44824469
for failure in pending_failures.drain(..) {
44834470
let receiver = HTLCDestination::NextHopChannel { node_id: Some(counterparty_node_id), channel_id: funding_txo.to_channel_id() };
@@ -5228,7 +5215,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
52285215
}
52295216

52305217
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<(), MsgHandleErrInternal> {
5231-
let chan_restoration_res;
5218+
let htlc_forwards;
52325219
let need_lnd_workaround = {
52335220
let mut channel_state_lock = self.channel_state.lock().unwrap();
52345221
let channel_state = &mut *channel_state_lock;
@@ -5263,7 +5250,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
52635250
}
52645251
}
52655252
let need_lnd_workaround = chan.get_mut().workaround_lnd_bug_4006.take();
5266-
chan_restoration_res = self.handle_channel_resumption(
5253+
htlc_forwards = self.handle_channel_resumption(
52675254
&mut channel_state.pending_msg_events, chan.get_mut(), responses.raa, responses.commitment_update, responses.order,
52685255
Vec::new(), None, responses.channel_ready, responses.announcement_sigs);
52695256
if let Some(upd) = channel_update {
@@ -5274,7 +5261,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
52745261
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))
52755262
}
52765263
};
5277-
post_handle_chan_restoration!(self, chan_restoration_res, counterparty_node_id);
5264+
5265+
if let Some(forwards) = htlc_forwards {
5266+
self.forward_htlcs(&mut [forwards][..]);
5267+
}
52785268

52795269
if let Some(channel_ready_msg) = need_lnd_workaround {
52805270
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;

0 commit comments

Comments
 (0)