-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix channel disable/enable race condition #10277
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
Open
ziggie1984
wants to merge
2
commits into
lightningnetwork:master
Choose a base branch
from
ziggie1984:fix-status-manager-disable-issue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 getting through this PR, but want to make sure that we don't end up with inconsistent state 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.
Eg: what if right after this check, the channel actually goes inactive? This is why we have the fallow period where we wait for the state to be consistent, before taking an action.
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.
An alternative here would be to just continue, so not modify the state and wait for the channel to be active long enough to flip in the other direction.
Uh oh!
There was an error while loading. Please reload this page.
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.
yes we can do that as well, so the acutal enable timer flipped the channel correctly.
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.
@gemini-code-assist what do you think about not changing the state here but rather let the enableRequest flip it? That however would create and additional channel_update
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 for the question, @ziggie1984. This is a good point to consider regarding the state transitions and network traffic.
Let's weigh the two approaches:
Current PR's approach (calling
m.chanStates.markEnabled(outpoint)
):chanStates
frompending disabled
toenabled
as soon asIsChannelActive
returns true. This directly "cancels" the pending disable from this function's perspective, ensuring internal consistency. Given thedisableInactiveChannels
function's role, it's robust for it to explicitly manage the state when it detects a channel that should not be disabled.markEnabled
always triggers achannel_update
announcement, and theenableRequest
mechanism also sends one, there could be two updates for the same state change.Alternative approach (just
continue
and letenableRequest
handle it):channel_update
if theenableRequest
is guaranteed to fire shortly after and handle the state transition and announcement.chanStates
would remainpending disabled
for a potentially significant period (up to 19 minutes based on the defaultenableTimer
mentioned in the PR description), even thoughm.cfg.IsChannelActive(chanID)
indicates it's active. This temporary inconsistency could lead to other parts of the system making decisions based on an outdated internal state. Relying solely on theenableRequest
to flip the state introduces a delay that might not be acceptable for internal state accuracy.My Recommendation:
I lean towards the current PR's approach of explicitly calling
m.chanStates.markEnabled(outpoint)
. Ensuring immediate internal state consistency is generally more critical for system correctness and predictability than avoiding a potentially redundant network announcement. An extrachannel_update
is typically less harmful than prolonged internal state inconsistency, especially when dealing with long timers like the 19-minuteenableTimer
.Ideally, the
markEnabled
function itself should be idempotent and intelligent enough to only issue achannel_update
announcement if the publicly announced state of the channel genuinely changes. If the channel was already consideredenabled
by theenableRequest
(which might have fired just before this check), thenmarkEnabled
should be a no-op in terms of external announcements. IfmarkEnabled
is not already designed this way, it might be worth reviewing its implementation to ensure it minimizes redundant announcements while maintaining internal state integrity.Uh oh!
There was an error while loading. Please reload this page.
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.
@gemini-code-assist I need to correct you tho, there will be no channelUpdate msg created in case we update the state of this channel in the disable method.
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.
Thank you for the clarification, @ziggie1984. That's a crucial detail that strengthens the argument for the current approach.
If
m.chanStates.markEnabled(outpoint)
does not generate achannel_update
message when called withindisableInactiveChannels
, then the primary 'con' I identified for this approach is removed. This means we get the benefit of immediate internal state consistency (marking the channel as enabled inchanStates
) without the overhead or potential redundancy of an extra network announcement.This makes the current implementation even more robust, as it ensures the internal state accurately reflects the channel's active status without unnecessary external side effects. My recommendation to keep the explicit
m.chanStates.markEnabled(outpoint)
stands firm, as it prioritizes internal data integrity, which is paramount for preventing subtle bugs and ensuring predictable system behavior.