Skip to content

Avoid querying the chain for outputs for channels we already have #1679

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

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

TheBlueMatt
Copy link
Collaborator

If we receive a ChannelAnnouncement message but we already have the
channel, there's no reason to do a chain lookup. Instead of
immediately calling the user-provided chain::Access when handling
a ChannelAnnouncement, we first check if we have the corresponding
channel in the graph.

Note that if we do have the corresponding channel but it was not
previously checked against the blockchain, we should still check
with the chain::Access and update if necessary.

@TheBlueMatt TheBlueMatt force-pushed the 2022-08-no-double-access branch 2 times, most recently from 629b66c to 78c0de1 Compare August 22, 2022 00:12
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Looks good to me besides the (I assume) test fixes

@TheBlueMatt TheBlueMatt force-pushed the 2022-08-no-double-access branch from 78c0de1 to d5cdf7a Compare August 22, 2022 19:35
wpaulino
wpaulino previously approved these changes Aug 22, 2022
dunxen
dunxen previously approved these changes Aug 22, 2022
@arik-so
Copy link
Contributor

arik-so commented Aug 23, 2022

Are we considering the possibility of reorgs, which might necessitate revalidating the same channel announcement? Not really a big edge case though, so I'm ready to ACK either way.

@TheBlueMatt TheBlueMatt dismissed stale reviews from dunxen and wpaulino via 16b9281 August 23, 2022 00:11
@TheBlueMatt
Copy link
Collaborator Author

Hmm, that's a good point, I pushed a commit to kinda handle that - we don't care too much if the peers are the same, and it seems kinda weird to bother handling the case where two peers were opening two channels at once, with different capacities, so instead we just re-validate only if the node ids dont match.

arik-so
arik-so previously approved these changes Aug 23, 2022
// We use the Node IDs rather than the bitcoin_keys to check for "equivalence"
// as we didn't (necessarily) store the bitcoin keys, and we only really care
// if the peers on the channel changed anyway.
if NodeId::from_pubkey(&msg.node_id_1) == chan.node_one && NodeId::from_pubkey(&msg.node_id_2) == chan.node_two {
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point, with a reorg, do we care if the capacity might have changed from what we had before for the same SCID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, I think to have that we'd have to have two nodes which are opening two channels at the same time with different capacities. Its definitely an edge-case, but I'm not sure how much we really care?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's a big deal. We'll definitely figure out how reliable that capacity is anyway.

dunxen
dunxen previously approved these changes Aug 23, 2022
If we receive a ChannelAnnouncement message but we already have the
channel, there's no reason to do a chain lookup. Instead of
immediately calling the user-provided `chain::Access` when handling
a ChannelAnnouncement, we first check if we have the corresponding
channel in the graph.

Note that if we do have the corresponding channel but it was not
previously checked against the blockchain, we should still check
with the `chain::Access` and update if necessary.
@TheBlueMatt TheBlueMatt dismissed stale reviews from dunxen and arik-so via 5847abd August 23, 2022 17:46
@TheBlueMatt TheBlueMatt force-pushed the 2022-08-no-double-access branch from 16b9281 to 5847abd Compare August 23, 2022 17:46
@TheBlueMatt
Copy link
Collaborator Author

Squashed without further change.

@codecov-commenter
Copy link

Codecov Report

Merging #1679 (5847abd) into main (b84b53a) will increase coverage by 0.09%.
The diff coverage is 92.78%.

@@            Coverage Diff             @@
##             main    #1679      +/-   ##
==========================================
+ Coverage   90.77%   90.86%   +0.09%     
==========================================
  Files          80       85       +5     
  Lines       44763    45714     +951     
  Branches    44763    45714     +951     
==========================================
+ Hits        40632    41539     +907     
- Misses       4131     4175      +44     
Impacted Files Coverage Δ
lightning-block-sync/src/lib.rs 93.23% <ø> (ø)
lightning-block-sync/src/test_utils.rs 93.46% <ø> (ø)
lightning-invoice/src/payment.rs 89.93% <0.00%> (+2.16%) ⬆️
lightning-net-tokio/src/lib.rs 77.16% <0.00%> (+0.30%) ⬆️
lightning-rapid-gossip-sync/src/lib.rs 90.90% <ø> (ø)
lightning/src/chain/mod.rs 68.18% <ø> (ø)
lightning/src/lib.rs 100.00% <ø> (ø)
lightning/src/ln/mod.rs 95.00% <ø> (ø)
lightning/src/util/chacha20poly1305rfc.rs 96.25% <ø> (ø)
lightning/src/util/config.rs 66.66% <0.00%> (-0.78%) ⬇️
... and 45 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@arik-so arik-so merged commit 17ae116 into lightningdevkit:main Aug 23, 2022
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.

5 participants