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

Store remote features in PeersDb #2978

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Jan 10, 2025

We only store information about our peers when we succeed in making an outgoing connection to them. The only information we stored was the address that we used when connecting. We now also store the features supported by our peer when we last connected to them.

It's important to note that this means that we previously didn't store peers that always connect to us (e.g. mobile wallet users that never have a stable address): we now store their features in our DB once we have a channel with them. For private peers that always connect to us, we will never store an address: it's their responsibility to connect back to us on disconnection.

t-bast added 2 commits January 9, 2025 18:21
We only store information about our peers when we succeed in making an
outgoing connection to them. The only informaiton we stored was the
address that we used when connecting. We now also store the features
supported by our peer when we last connected to them.

It's important to note that this means that we currently don't store
peers that always connect to us (e.g. mobile wallet users that never
have a stable address): we will address that in the next commit.
Once we have a channel with a peer that connected to us, we store their
details in our DB. We don't store the address they're connecting from,
because we don't know if we will be able to connect to them using this
address, but we store their features.
@t-bast t-bast force-pushed the store-remote-peer-features branch from 2092ead to 0c9b78c Compare January 10, 2025 11:41
@t-bast t-bast marked this pull request as ready for review January 10, 2025 14:58
@t-bast t-bast requested review from thomash-acinq and pm47 January 10, 2025 15:00
statement.setBytes(3, encodedFeatures)
statement.executeUpdate()
}
case None =>
Copy link
Member

Choose a reason for hiding this comment

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

From the name of the function, I would guess that addOrUpdatePeer(_, NodeInfo(features, None)) would remove the previously stored address. You should document it. Maybe there should even be two functions, one for updating only the features and one for updating both the features and the address.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, this was confusing, thanks for pointing it out. I extracted it to a different function in ad482dc.

case Some(remoteFeatures) => Some(remoteFeatures)
case None => nodeParams.db.peers.getPeer(remoteNodeId).map(nodeInfo => LastRemoteFeatures(nodeInfo.features, written = true))
}
replyTo ! PeerInfo(self, remoteNodeId, stateName, remoteFeatures_opt.map(_.features), None, d.channels.values.toSet)
Copy link
Member

Choose a reason for hiding this comment

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

Why not give the address too?

Copy link
Member Author

@t-bast t-bast Jan 13, 2025

Choose a reason for hiding this comment

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

In the disconnected case, we don't store the peer's address (in DisconnectedData). We may have one if we connected and then disconnected, or we may not. We could start storing this (optional) remote address in the disconnected case, but I don't know if we would gain much: the scope of this PR is rather to store the remote features, so it's something we'd do in a different PR if we think it's useful?

// If this is an incoming connection, we only store the peer details in our DB if we have channels with them.
// Otherwise nodes could DoS by simply connecting to us to force us to store data in our DB.
// We don't update the remote address, we don't know if we would successfully connect using the current one.
nodeParams.db.peers.addOrUpdatePeer(remoteNodeId, NodeInfo(connectionReady.remoteInit.features, None))
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a write here? Isn't it enough to write when the channel is ready?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I removed it in ad482dc

- Use separate function when updating features only
- Remove DB write before channel ready for incoming connection
@t-bast t-bast requested a review from thomash-acinq January 13, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants