Skip to content
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

db: Retrieve peer ID if it exists or create the peer if not #3801

Merged
merged 1 commit into from
Jun 30, 2020

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Jun 29, 2020

We were assuming wallet_channel_insert that there cannot be a matching peer
if our in-memory representation isn't bound to it (dbid == 0). If we then
attempt to create the peer, and we already had one it'd cause a unique
constraint violation. As far as I can tell this could end up happening if we
have an uncommitted channel, and then exited without cleanup (tal_destructor
on the uncommitted channel not running). This could then leave the peer in the
DB. This is because the constraint that every peer has at least one channel is
not enforce at DB level, but rather in destructors that may or may not run.

I tried to reproduce the issue in pytest, but was unsuccessful, suggesting I don't
fully capture the causes yet.

Notice that an alternative to this would be adding yet another cleanup-on-start
but that feels even more heavy handed, and if implemented wrongly might
itself result in inconsistencies, which is why I went for the load-or-create method.

Changelog-Fixed: Fixed a failing assertion if we reconnect to a peer that we had a channel with before, and then attempt to insert the peer into the DB twice.

@cdecker cdecker added this to the v0.9.0 milestone Jun 29, 2020
@cdecker cdecker self-assigned this Jun 29, 2020
@cdecker cdecker requested a review from niftynei June 29, 2020 11:44
wallet/wallet.c Outdated Show resolved Hide resolved
We were assuming `wallet_channel_insert` that there cannot be a matching peer
if our in-memory representation isn't bound to it (`dbid == 0`). If we then
attempt to create the peer, and we already had one it'd cause a unique
constraint violation. As far as I can tell this could end up happening if we
have an uncommitted channel, and then exited without cleanup (`tal_destructor`
on the uncommitted channel not running). This could then leave the peer in the
DB. This is because the constraint that every peer has at least one channel is
not enforce at DB level, but rather in destructors that may or may not run.

Changelog-Fixed: Fixed a failing assertion if we reconnect to a peer that we had a channel with before, and then attempt to insert the peer into the DB twice.
@cdecker
Copy link
Member Author

cdecker commented Jun 30, 2020

Range-diff here

Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

ACK 5782596

@rustyrussell rustyrussell merged commit 7b899da into ElementsProject:master Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants