Skip to content

Forward over substitute channels #1578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9864a26
Add `counterparty_node_id` to `short_to_id` map
ViktorTigerstrom May 17, 2022
0780fb9
Rename `short_to_id` map to `short_to_chan_info`
ViktorTigerstrom Jun 9, 2022
7833589
Add id_to_peer map
ViktorTigerstrom Jun 3, 2022
b0975eb
Add `ChannelManager:id_to_peer` map coverage test
ViktorTigerstrom Jun 6, 2022
d3667d9
Add `counterparty_node` to test macros
ViktorTigerstrom May 27, 2022
6c62533
Store channels per-peer
ViktorTigerstrom May 25, 2022
519fcb4
f - Store per peer: aquire locks inside get_channel_ref
ViktorTigerstrom Jun 9, 2022
c37b984
f - Make per_peer_state a FairRwLock
ViktorTigerstrom Jun 6, 2022
f7b51d2
f - Remove unreacable branches that can be reached
ViktorTigerstrom Jun 6, 2022
2c112d7
f - Store channels per-peer: Update per_peer_state docs
ViktorTigerstrom Jun 7, 2022
7b594ee
Remove unnecessary `per_peer_state` branch
ViktorTigerstrom Jun 10, 2022
7e9ac7b
Avoid retaking locks
ViktorTigerstrom Jun 6, 2022
6c4b80d
Update failure to query `Channel` error messages
ViktorTigerstrom Jun 6, 2022
4991456
Add duplicate temporary_channel_id for 2 peers test
ViktorTigerstrom May 31, 2022
ae665ce
Add handle unkown peer test
ViktorTigerstrom Jun 13, 2022
ef4107a
Enable htlc forwarding over substitute channels
ViktorTigerstrom Jun 20, 2022
1d44945
Test htlc forwarding over substitute channels
ViktorTigerstrom Jun 20, 2022
1dec1f9
f - Move creation of CommitmentUpdate structs
ViktorTigerstrom Jun 27, 2022
6b9a261
-f DRY up htlc_msg macros
ViktorTigerstrom Jun 27, 2022
13dbfe3
f - cleanup channel selection order
ViktorTigerstrom Jun 29, 2022
92a067c
f - cleanup tests
ViktorTigerstrom Jun 29, 2022
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
27 changes: 12 additions & 15 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use core::ops::Deref;

#[cfg(any(test, feature = "std"))]
use std::time::Instant;
use std::any::Any;
use util::crypto::sign;

// We hold various information about HTLC relay in the HTLC objects in Channel itself:
Expand Down Expand Up @@ -3015,22 +3016,18 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
}}
}

macro_rules! add_update_add_htlc {
($add_htlc_msg: expr, $channel_id: expr, $counterparty_node_id: expr) => {{
macro_rules! add_update_htlc_msg {
($htlc_msg: expr, $channel_id: expr, $counterparty_node_id: expr) => {{
add_channel_key!($channel_id, $counterparty_node_id);
if let hash_map::Entry::Occupied(mut entry) = htlcs_msgs_by_id.entry($channel_id) {
let msgs_entry = entry.get_mut();
msgs_entry.0.push($add_htlc_msg);
}
}}
}

macro_rules! add_update_fail_htlc {
($fail_htlc_msg: expr, $channel_id: expr, $counterparty_node_id: expr) => {{
add_channel_key!($channel_id, $counterparty_node_id);
if let hash_map::Entry::Occupied(mut entry) = htlcs_msgs_by_id.entry($channel_id) {
let msgs_entry = entry.get_mut();
msgs_entry.1.push($fail_htlc_msg);
if let Some(msg) = (&$htlc_msg as &Any).downcast_ref::<msgs::UpdateAddHTLC>() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not happy with this downcast solution, but couldn't get a match statement to work. If you can think of a better way of doing this, or if you prefer avoiding this DRY up, please let me know!

msgs_entry.0.push(msg.clone());
} else if let Some(msg) = (&$htlc_msg as &Any).downcast_ref::<msgs::UpdateFailHTLC>() {
msgs_entry.1.push(msg.clone());
} else {
panic!("Only UpdateAddHTLC or UpdateFailHTLC msgs supported for add_update_htlc_msg");
}
}
}}
}
Expand Down Expand Up @@ -3154,7 +3151,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
match update_add {
Some(msg) => {
log_info!(self.logger, "Will forward HTLC with payment_hash {}, over channel {}", log_bytes!(payment_hash.0), log_bytes!(chan_id));
add_update_add_htlc!(msg, chan_id, counterparty_node_id);
add_update_htlc_msg!(msg, chan_id, counterparty_node_id);
},
None => {
// Nothing to do here...we're waiting on a remote
Expand Down Expand Up @@ -3197,7 +3194,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
// the chain and sending the HTLC-Timeout is their problem.
continue;
},
Ok(Some(msg)) => { add_update_fail_htlc!(msg, forward_chan_id, counterparty_node_id); },
Ok(Some(msg)) => { add_update_htlc_msg!(msg, forward_chan_id, counterparty_node_id); },
Ok(None) => {
// Nothing to do here...we're waiting on a remote
// revoke_and_ack before we can update the commitment
Expand Down