Repository navigation
Conversation
|
👋 Thanks for assigning @tankyleo as a reviewer! |
tankyleo
left a comment
There was a problem hiding this comment.
LGTM, one nit can we squash all the commits for the peer store mutations into a single one ?
Adding a peer inserted it into the in-memory set before the write was awaited, so a failed write followed by a retry reported success while the peer was gone after a restart. Removing a peer went through separate hand-rolled logic, rewrote the peer set even when the peer was unknown, and thereby could fail for a removal with nothing to do. Route both mutations through a single helper that applies the change to a copy of the peer set, persists it, and only then publishes it to readers, skipping the write if nothing changed. As a write that fails or is cancelled may still have reached the store, the next mutation rewrites the peer set even if it changes nothing, so that, e.g., a removed peer is not reconnected to after a restart. Co-Authored-By: HAL 9000
The number of persisted peers was written as a plain `u16`, so a peer set of more than 65535 entries had its count truncated and most of its peers silently dropped on the next restart. The event queue had the same issue, which was fixed by switching to `CollectionLength`. Do the same for the peer store. As `CollectionLength` encodes counts below `u16::MAX` exactly as before, previously persisted peer sets are still read and smaller ones are still written unchanged. As the count read from disk is thereby no longer bounded to `u16::MAX`, we also stop preallocating for it, so that a corrupted count fails to read rather than exhausting memory. Co-Authored-By: HAL 9000
1497cf4 to
d968165
Compare
Not quite sure why it's preferable, but done. |
For context this is the reason I asked: 8544da8 introduced a regression by skipping writes when removing a peer absent from memory, potentially leaving it in storage after an earlier failed or cancelled add had actually persisted it. 1497cf4 fixed this by tracking unconfirmed writes and forcing the next mutation to persist even when the in-memory map was unchanged. |
Node::connect(..., persist=true) and open_channel kept the first stored address, so a later working address was never used for reconnect (lightningdevkit#700). upsert_peer replaces the address through the persist-first update_peers path from lightningdevkit#1234. connect and open_channel call it only when this call dialed the requested address. An already-connected peer keeps add_peer, so an unverified address cannot overwrite a working one. The LSPS2 receive path stays add_peer (lightningdevkit#1147). Co-authored-by: Bartok <259807879+Bartok9@users.noreply.github.com> Assisted-by: goose (AI)
Several recent PRs each fixed one symptom of the peer store's persistence
handling. This addresses them at the store level instead:
add_peerandremove_peernow share one mutation path that persiststhe updated peer set before publishing it to readers, so the in-memory
set can no longer get ahead of the persisted one and a retry after a
failed write persists again.
CollectionLength, as Use CollectionLength for the persisted event queue length #1230 did for theevent queue, and we no longer preallocate based on it.
applied by the store), the next mutation rewrites the peer set even if it
changes nothing.
Supersedes #1150 and the peer-store half of #1215. It also replaces the
PeerStorerewrite in #1175, which can be rebased to only addupsert_peerand its call-site changes on top. #1149 needed the #1150 fix and can now be rebased onto this.Closes #1142.