Repository navigation
Conversation
open_channel_inner created the channel and only then wrote the peer to the peer store. If that write failed, the API returned PersistenceFailed for a channel that was already live, and a caller retrying would open a second channel. Persist the peer first, so a persistence failure is returned before anything is initiated. If channel creation then fails and the peer was only stored for this attempt, remove it again so we don't keep reconnecting to it, unless we have a channel with it (a concurrent open_channel to the same peer may have succeeded in the meantime), as remove_peer_after_reconnect does. Co-authored-by: Claude <noreply@anthropic.com>
PeerWriteFailingStore wraps an InMemoryStore and fails writes of the persisted peer list while a flag is set. With the flag on, open_channel returns PersistenceFailed and no channel exists. Once the store recovers, a retry opens exactly one channel and the peer is persisted. Co-authored-by: Claude <noreply@anthropic.com>
|
I've assigned @tnull as a reviewer! |
tnull
left a comment
There was a problem hiding this comment.
Thanks! Let's drop the cleanup part please.
| .is_empty(); | ||
| if !peer_was_stored && !has_channels { | ||
| if let Err(e) = | ||
| self.runtime.block_on(self.peer_store.remove_peer(&peer_info.node_id)) |
There was a problem hiding this comment.
Hmm, I think this cleanup is race-y for concurrent calls of open_channel. Let's simplify things further and just move the add_peer line up in this PR.
Eventually we'll want to do a larger PeerStore refactor that is more robust.
There was a problem hiding this comment.
Thanks, dropped in aa9424a. The add_peer call is the only change left in open_channel_inner: it now runs before create_channel, and nothing removes the peer if creation fails, so a failed attempt leaves the peer stored. (The commit message says "as before this PR" about that, which is wrong: before this PR a failed creation never stored the peer.) cargo check --tests and cargo fmt --check pass. I could not rerun channel_open_fails_cleanly_when_peer_persistence_fails here because my environment cannot download bitcoind; that test only covers the failed peer write, which this commit does not touch.
The removal raced with concurrent open_channel calls to the same peer. A failed creation now keeps the peer it stored, as before this PR; a later PeerStore refactor can revisit this. Co-authored-by: Claude <noreply@anthropic.com>
tnull
left a comment
There was a problem hiding this comment.
I don't think we need the big regression test, and the comment should also not tell the 'history' of the code. I think we can just reduce this to a +1/-1 diff really, just moving the one line up.
Fixes #1143. Supersedes #1149, rebased onto current
mainas two additive commits, as requested there.open_channel_innercreated the channel and only then wrote the peer to the peer store. If that write failed, the API returnedPersistenceFailedfor a channel that was already live, and a caller retrying would open a second channel (and push the amount again).This takes the first option from the issue: the peer is persisted before
create_channel, so a persistence failure is returned before anything is initiated, and before the fee-rate override is registered. If channel creation then fails, the peer stays stored: removing it again raced with concurrentopen_channelcalls to the same peer, so that cleanup was dropped on review and is left to a laterPeerStorerefactor.The
PeerStore::add_peercaching issue the issue mentions is left to #1150, as agreed on #1149.Commits
Persist the peer before initiating a channel:src/lib.rs.Test that a failed peer write does not leave a live channel: integration test with aKVStorewrapper that fails writes of the peer list on demand. With the failure on,open_channelreturnsPersistenceFailedand no channel exists; once the store recovers, a retry opens exactly one channel and the peer is persisted.Drop the peer cleanup after a failed channel creation: removes the cleanup from commit 1, as asked on review. With it,open_channel_inneronly movesadd_peerbeforecreate_channel(+5/−1).Testing on
main0fc5565:cargo test --lib483 passed, andcargo clippy --all-targetscompiles the integration tests. The only new clippy notes are in the new test and match constructs already used by the existing tests in that file (EsploraSyncConfig::default()then a field assignment,node_entropy.into()). rustfmt is clean. I couldn't run the bitcoind/electrs integration tests in my environment.🤖 Generated with Claude Code
https://claude.ai/code/session_014cRzwuyJe8BGwXowsQ3kpw