-
Notifications
You must be signed in to change notification settings - Fork 386
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
Move short_to_chan_info
into standalone lock
#1639
Move short_to_chan_info
into standalone lock
#1639
Conversation
}; | ||
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would have preferred to place this cleanup in the final commit, but keeping them in the first commit messed up the macro. I hope that's ok.
Realized I need to go through this closer another time, as the current consistency guarantees ensures that the channel is guaranteed to exist in the While open the pull request when I've checked this further. |
d9eb4c1
to
1da7a95
Compare
Added a fixup commit that ensures that the consistency guarantees that any Also rebased this on main, now that the blocking PR has been merged. |
lightning/src/ln/channelmanager.rs
Outdated
@@ -1256,9 +1272,12 @@ macro_rules! handle_error { | |||
} | |||
|
|||
macro_rules! update_maps_on_chan_removal { | |||
($self: expr, $short_to_chan_info: expr, $channel: expr) => { | |||
($self: expr, $channel: expr) => { | |||
// The lockorder for id_to_peer is prior to short_to_chan_info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but there's also no reason to hold both locks at the same time here - just do self.id_to_peer.lock().unwrap().remove(&$channel.channel_id());
all in one statement at the top and then you don't have to worry about it :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 1891450
lightning/src/ln/channelmanager.rs
Outdated
/// SCIDs being added once the funding transaction is confirmed at the channel's required | ||
/// confirmation depth. | ||
/// | ||
/// Consistancy guarantees with the `channel_state::by_id` map, guarantees that any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I mean while this patch may be fine, I'd kinda prefer if we just not have guarantees to begin with - is there a reason we need to have these guarantees, or can we just not guarantee anything and handle the None
case in the by_id
lookups when we fetch from this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure I'll change to that instead :)! I did it this way mostly just to make this PR not change the current consistency guarantees, but if we're ok with changing that, I see no reason why we can't do what you suggest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I mean the nice thing about this PR is its relatively small-ish, and aside from argument changes, is quite reviewable, so its totally find to slip in a change like that here, as it can also make future things easier to review. Plus it seems like a more robust design anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 919ec65
1da7a95
to
edbff4c
Compare
Thanks for the review @TheBlueMatt! I've addressed your feedback with the latest pushed commits. Unfortunately I had to rebase to drop the patch I made before, but I rebased on the same HEAD as before. |
lightning/src/ln/channelmanager.rs
Outdated
let forward_chan_id = match channel_state.short_to_chan_info.get(&short_chan_id) { | ||
Some((_cp_id, chan_id)) => chan_id.clone(), | ||
None => { | ||
macro_rules! fail_pending_forwards { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super happy about this macro, and would prefer to break it out into a separate function due to the added complexity. But I figured process_pending_htlc_forwards
was probably kept large with macros for efficacy reasons, so opted for the new macro instead. Let me know if my assumptions are wrong, and you'd prefer to break this out :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, I just know that nested macros are not fun to debug 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah definitely agree 😬...
lightning/src/ln/channelmanager.rs
Outdated
@@ -4098,7 +4129,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
let mut expected_amt_msat = None; | |||
let mut valid_mpp = true; | |||
for htlc in sources.iter() { | |||
if let None = channel_state.as_ref().unwrap().short_to_chan_info.get(&htlc.prev_hop.short_channel_id) { | |||
if let None = self.short_to_chan_info.read().unwrap().get(&htlc.prev_hop.short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check that the channel is available now, too. And while we're at it, let's check that the channel isn't shutting down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah good catch! Fixed with 1f01103
lightning/src/ln/channelmanager.rs
Outdated
hash_map::Entry::Occupied(_) => continue, | ||
hash_map::Entry::Vacant(_) => return scid_candidate | ||
match short_to_chan_info.get(&scid_candidate) { | ||
Some((_cp_id, _chan_id)) => continue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some((_cp_id, _chan_id)) => continue, | |
Some(_) => continue, |
lightning/src/ln/channelmanager.rs
Outdated
@@ -5819,7 +5848,7 @@ where | |||
|
|||
fn get_relevant_txids(&self) -> Vec<Txid> { | |||
let channel_state = self.channel_state.lock().unwrap(); | |||
let mut res = Vec::with_capacity(channel_state.short_to_chan_info.len()); | |||
let mut res = Vec::with_capacity(self.short_to_chan_info.read().unwrap().len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol let's not take a lock just for the capacity here, just use the by_id map instead, its close enough.
Thanks! Addressed the latest feedback with 1f01103 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically there, I think.
@@ -5127,7 +5168,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
fn internal_channel_update(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelUpdate) -> Result<NotifyOption, MsgHandleErrInternal> { | |||
let mut channel_state_lock = self.channel_state.lock().unwrap(); | |||
let channel_state = &mut *channel_state_lock; | |||
let chan_id = match channel_state.short_to_chan_info.get(&msg.contents.short_channel_id) { | |||
let chan_id = match self.short_to_chan_info.read().unwrap().get(&msg.contents.short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given there's no consistency requirements anymore, you can move the channel_state lock down below the short_to_chan_info lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 41d275d
Codecov ReportBase: 90.79% // Head: 90.83% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1639 +/- ##
==========================================
+ Coverage 90.79% 90.83% +0.04%
==========================================
Files 87 86 -1
Lines 47604 46422 -1182
Branches 47604 46422 -1182
==========================================
- Hits 43221 42168 -1053
+ Misses 4383 4254 -129
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good to me. I'll try to give it another pass today, but not 100% confident with pending forwards yet :)
lightning/src/ln/channelmanager.rs
Outdated
let forward_chan_id = match channel_state.short_to_chan_info.get(&short_chan_id) { | ||
Some((_cp_id, chan_id)) => chan_id.clone(), | ||
None => { | ||
macro_rules! fail_pending_forwards { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, I just know that nested macros are not fun to debug 🙈
@@ -2440,7 +2464,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
} | |||
} | |||
|
|||
let id = match channel_lock.short_to_chan_info.get(&path.first().unwrap().short_channel_id) { | |||
let id = match self.short_to_chan_info.read().unwrap().get(&path.first().unwrap().short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we should move this above the let payment_entry = ...
line above, otherwise short_to_chan_info
lock order also depends on pending_outbound_payments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, good catch! Thanks :)
Fixed with 569f172
lightning/src/ln/channelmanager.rs
Outdated
@@ -5579,14 +5620,14 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
/// | |||
/// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager | |||
pub fn get_phantom_scid(&self) -> u64 { | |||
let mut channel_state = self.channel_state.lock().unwrap(); | |||
let short_to_chan_info = self.short_to_chan_info.read().unwrap(); | |||
let best_block = self.best_block.read().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change this to just get the block height within a scope for use below. Otherwise a dependency between best_block
and short_to_chan_info
is introduced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :)
Fixed with 82b2138
lightning/src/ln/channelmanager.rs
Outdated
macro_rules! fail_pending_forwards { | ||
() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you can get rid of the macro with something like:
macro_rules! fail_pending_forwards { | |
() => { | |
let forward_chan_id_opt = match self.short_to_chan_info.read().unwrap().get(&short_chan_id) | |
.map(|(_cp_id, chan_id)| chan_id.clone()); | |
if forward_chan_id_opt.is_none() || !channel_state.by_id.contains_key(forward_chan_id_opt.unwrap()) { | |
but I haven't actually completed this patch myself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks for the suggestion :)!
That change would indeed work when only taking this PR into account. Sadly though, that change would not help when taking #1507 into consideration as well, which I'd like this PR to prepare for. 1507 is quite huge, so I'd like to do as many changes as possible within this PR, to make 1507 as reviewable as possible.
In 1507, we will lock the new channel lock
in this scope by using the info retrieved from short_to_chan_info
(The counterparty_node_id
and the channel_id
). Therefore we wouldn't be able to check that both short_to_chan_info
contained a value for the scid
and check that the new channel lock
contains the channel for the unwrapped short_to_chan_info
info in the same if
clause, unless we'd take the new channel lock
temporarily just for the contains check. Though by taking the channel lock
temporarily, we would still need the Vaccant
check below for the channel lock
, hence requiring the second call site for the code in fail_pending_forwards
:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, worth a shot!
I think the fixups may be out of order? Correct me if I'm wrong, but it helps me when a fixup is next to the commit it's fixing up |
41d275d
to
913daf8
Compare
Thank you for the reviews @valentinewallace and @dunxen :)! Sorry for taking so long to address the feedback, I've been traveling.
Oh yes, you are correct. Thanks for informing me about that it helps in the review process to move up the fixup commits to the correct order. I was incorrectly under the impression that it was less confusing to not move them, but now I know better :). I'll move them up from now on. |
Looks like this needs rebase now :/ |
913daf8
to
3e3d954
Compare
Rebased on upstream without changes except fixing minor merge conflicts. |
lightning/src/ln/channelmanager.rs
Outdated
$short_to_chan_info.remove(&$channel.outbound_scid_alias()); | ||
($self: expr, $channel: expr) => { | ||
{ | ||
let mut id_to_peer = $self.id_to_peer.lock().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why not keep the line as-is previously vs assigning the mutexguard? Then you can drop the scope (as temporaries are drop'd automatically at the ;
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 😅
Fixed with: e47fc06
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 😅 Fixed with: e47fc06
Hmm did this fix end up getting dropped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I moved this change to the follow-up PR #1795. It's getting a bit unnecessary with a separate PR for the follow-ups now that I'm already doing some small fixes in this PR hah, so I will close that PR and bring the fixups into this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood, since this is basically mergeable I support keeping this fix in followup! But up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry missed this until I had already pushed the followups with this PR yesterday. Hope that's ok :)
@@ -2246,7 +2263,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
if let &PendingHTLCRouting::Forward { ref short_channel_id, .. } = routing { | |||
if let Some((err, code, chan_update)) = loop { | |||
let mut channel_state = self.channel_state.lock().unwrap(); | |||
let id_option = channel_state.short_to_chan_info.get(&short_channel_id).cloned(); | |||
let id_option = self.short_to_chan_info.read().unwrap().get(&short_channel_id).cloned(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be above the channel_state lock, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sure :)! Sadly we're already holding the channel_state
when taking the short_to_chan_info
lock in multiple other places, but might as well fix that here.
@@ -2428,6 +2452,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
let err: Result<(), _> = loop { | |||
let mut channel_lock = self.channel_state.lock().unwrap(); | |||
|
|||
let id = match self.short_to_chan_info.read().unwrap().get(&path.first().unwrap().short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should short_to_chan_info
comment be updated in consequence "Locked after channel_state
" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we can't remove the lock order requirement for short_to_chan_info
to be locked after the channel_state
lock with this PR, as it's still required in multiple other places in the code, but with #1507 we'll be able to remove that lock order however :).
I think that this order change here and above mainly a preparation for that PR, and is ok here since we only take the short_to_chan_info
lock temporarily and drop it before taking the channel_state
lock.
I agree though that this is a bit confusing, and if you'd like, I could remove this temporary order change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with the order, if this hunk were moved above the channel_lock it would be fine - because we take the read lock and then copy out of it the read lock is dropped at the semicolon after the match, which means no lock order would be implied. Not a big deal, though, its fine to leave it for now, just nice to avoid holding both locks at the same time if we can avoid it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3e3d954
to
9e341c8
Compare
Addressed the latest feedback, and restricted the access for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, first parse
@@ -2428,6 +2452,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
let err: Result<(), _> = loop { | |||
let mut channel_lock = self.channel_state.lock().unwrap(); | |||
|
|||
let id = match self.short_to_chan_info.read().unwrap().get(&path.first().unwrap().short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should short_to_chan_info
comment be updated in consequence "Locked after channel_state
" ?
@@ -2426,8 +2447,12 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier); | |||
|
|||
let err: Result<(), _> = loop { | |||
let mut channel_lock = self.channel_state.lock().unwrap(); | |||
let id = match self.short_to_chan_info.read().unwrap().get(&path.first().unwrap().short_channel_id) { | |||
None => return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, error message could be "No channel found with first-hop", historically ChannelUnavailable
has been used to flag a channel !is.live()
, e.g when the monitor is not ready. I think it's more accurate to indicate non-availability in a way different than non-presence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, I didn't know this, so thanks for informing me! Is it mainly the error message that we'd like to change, or would we like to create a new APIError
variant as well?
@@ -2506,7 +2526,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
}, | |||
None => { insert_outbound_payment!(); }, | |||
} | |||
} else { unreachable!(); } | |||
} else { | |||
return Err(APIError::ChannelUnavailable{err: "No channel available with first hop!".to_owned()}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could recall the lack of consistency between short_to_chan_info
and by_id
, what we hit afaiu. Or move this indication as a general comment of short_to_chan_info
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm not sure if you mean that we'd like to change the error message here to indicate to the user the lack between the short_to_chan_info
and the by_id
maps, or if you mean that we should just add a code comment here to indicate it. I don't think we should change the message to surface the reason for the problem to the user, as neither the short_to_chan_info
nor the by_id
map are public to the user, and it would therefore make no sense to refer to them in the message.
I'll add a code comment here to note why this was triggered :). See: a8b9fd0
lightning/src/ln/channelmanager.rs
Outdated
let forward_chan_id = match channel_state.short_to_chan_info.get(&short_chan_id) { | ||
Some((_cp_id, chan_id)) => chan_id.clone(), | ||
None => { | ||
macro_rules! fail_pending_forwards { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, I think of the phantom invoices handling logic is actually in this branch (L3168-3193), so I'm not sure about qualifying it as "fail_pending_forwards" as in some case we might fetch the phantom payment.
Not necessarily in that PR, but I think it could be interesting to break up process_pending_htlc_forwards
in few smaller helpers, especially as here we're starting to reuse some code paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good point! Perhaps we'd like to name the macro to something else than fail_pending_forwards
then? I'll rename it to forwarding_channel_not_found
temporarily, but if you have a better suggestion let me know :).
I also agree that process_pending_htlc_forwards
is starting to get very long and complicated, and would be nice to brake up if possible. Adding this macro also makes everything more complicated and harder to debug.
Name changed with: c95961e
@@ -5907,14 +5943,15 @@ where | |||
// enforce option_scid_alias then), and if the funding tx is ever | |||
// un-confirmed we force-close the channel, ensuring short_to_chan_info | |||
// is always consistent. | |||
let mut short_to_chan_info = self.short_to_chan_info.write().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still confused here by the what is the correct lock order between short_to_chan_info
and channel_state
one L5895
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1639 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM. Please squash and lets land it!
$pending_msg_events.push(events::MessageSendEvent::SendChannelReady { | ||
node_id: $channel.get_counterparty_node_id(), | ||
msg: $channel_ready_msg, | ||
}); | ||
// Note that we may send a `channel_ready` multiple times for a channel if we reconnect, so | ||
// we allow collisions, but we shouldn't ever be updating the channel ID pointed to. | ||
let outbound_alias_insert = $short_to_chan_info.insert($channel.outbound_scid_alias(), ($channel.get_counterparty_node_id(), $channel.channel_id())); | ||
let mut short_to_chan_info = $self.short_to_chan_info.write().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we scope this lock (or the macro, by adding extra {}s in the macro)? I'm not sure its required but I also don't really understand the rules for drop when leaving a macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with the latest push. I didn't push in a separate fixup commit, hope that's ok!
@@ -2428,6 +2452,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana | |||
let err: Result<(), _> = loop { | |||
let mut channel_lock = self.channel_state.lock().unwrap(); | |||
|
|||
let id = match self.short_to_chan_info.read().unwrap().get(&path.first().unwrap().short_channel_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with the order, if this hunk were moved above the channel_lock it would be fine - because we take the read lock and then copy out of it the read lock is dropped at the semicolon after the match, which means no lock order would be implied. Not a big deal, though, its fine to leave it for now, just nice to avoid holding both locks at the same time if we can avoid it.
1ea75e3
to
590eae3
Compare
Squashed and addressed latest feedback :)! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, feel free to take or leave nits
lightning/src/ln/channelmanager.rs
Outdated
$short_to_chan_info.remove(&$channel.outbound_scid_alias()); | ||
($self: expr, $channel: expr) => { | ||
{ | ||
let mut id_to_peer = $self.id_to_peer.lock().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question 😅 Fixed with: e47fc06
Hmm did this fix end up getting dropped?
Thanks @dunxen & @valentinewallace. |
a38c9c4
590eae3
to
a38c9c4
Compare
Addressed the latest feedback, and also brought in the followups from #1795 into this PR (ie. scope fix for I fixed up these changes into the corresponding commit already as they were minor. I hope that's ok :) |
LGTM after rebase |
a38c9c4
to
acf17e7
Compare
Rebased on main. The only changes were merge conflict fixes 🚀! |
Grrrrr, I'm sorry, this was dumb #1639 (comment) . We should not be checking I think what i was thinking is we should check if the peer is online before claiming, which, like, maybe, but its not critical, and we'd need to check specifically only for if they're connected. |
acf17e7
to
07664c2
Compare
Removed the |
As the `channel_state` (`ChannelHolder`) struct will be removed, this commit moves the `short_to_chan_info` map from that lock into a seperate lock.
As the `short_to_chan_info` has been moved out of the `channel_state` to a standalone lock, several macros no longer need the `channel_state` passed into the macro.
As the `short_to_chan_info` map has been removed from the `channel_state`, there is no longer any consistency guarantees between the `by_id` and `short_to_chan_info` maps. This commit ensures that we don't force unwrap channels where the channel_id has been queried from the `short_to_chan_info` map.
Refactor `process_pending_htlc_forwards` to ensure that both branches that fails `pending_forwards` are placed next to eachother for improved readability.
07664c2
to
b368941
Compare
Sorry, reverted once more to just remove the |
Based on #1638 and a prerequisite for #1507.
As the
channel_state
(ChannelHolder
) struct will be removed, this commit moves theshort_to_chan_info
map from that lock into a separate lock, and cleans up a few macros that can be cleaned up due to moving it into a separate lock.