Prevent channel_id collisions - #3337
Merged
Merged
Conversation
If the first DB write of a channel fails, we want to abort the channel immediately, otherwise our state may be unusable. If for some reason we already have a channel (for example because of a partial restore from a DB backup), we want to avoid overwriting this state as well.
We add a global, concurrent map that keeps track of every temporary and final `channel_id` being used. We always add to this map before creating channel actors or transitioning to a final `channel_id` (and thus before storing channel data in the DB). We only remove from that map when a channel actor dies: no other channel can be associated with the corresponding temporary or final `channel_id` since the channel was created after registering the IDs.
pm47
approved these changes
Jul 28, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If the first DB write of a channel fails, we want to abort the channel immediately, otherwise our state may be unusable. If for some reason we already have a channel (for example because of a partial restore from a DB backup), we want to avoid overwriting this state as well. This is implemented in the first commit of this PR.
In the second commit, we prevent
channel_idcollisions across peers: while highly unlikely (since they depend on the actual funding transaction for single-funding and the random revocation basepoint for dual-funding), they would trigger a force-close. We thus add a global, concurrentchannel_idmap, which can be reused in the future for accounting.