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

Offers: send invoice request #87

Merged
merged 24 commits into from
Mar 7, 2024
Merged

Offers: send invoice request #87

merged 24 commits into from
Mar 7, 2024

Conversation

orbitalturtle
Copy link
Collaborator

@orbitalturtle orbitalturtle commented Jan 2, 2024

Rewrote the send invoice logic with #85 in mind. I agree it seems cleaner :) I realize #85 wasn't intended for merge, but I didn't need to make many significant changes to the structure, so I just made a few tweaks to the commits here.

Also about to write a few thoughts/questions inline.

Replaces #81.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@orbitalturtle
Copy link
Collaborator Author

It looks like the clippy error is coming from configure_me.

@orbitalturtle orbitalturtle changed the title offers: send invoice request Offers: send invoice request Jan 23, 2024
@carlaKC
Copy link
Collaborator

carlaKC commented Jan 29, 2024

I realize #85 wasn't intended for merge, but I didn't need to make many significant changes to the structure, so I just made a few tweaks to the commits here.

Happy for you to add those as fixups to the original commits + squash and you can just take it over 👍 ie, we merge what's in #85 in here

README.md Outdated Show resolved Hide resolved
src/lndk_offers.rs Outdated Show resolved Hide resolved
src/lndk_offers.rs Outdated Show resolved Hide resolved
src/lndk_offers.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/onion_messenger.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
// MessengerState tells us whether our onion messenger is still starting up is ready to start
// forwarding messages.
#[derive(Debug)]
pub enum MessengerState {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than add a whole state machine, can we have a one-shot channel and close it when we're done with startup? Also comes with the benefit that we can select on shutdown / channel close and then we don't have to have any X second / magic number wait -> it'll either exit if we've given up or yield exactly when the onion messenger has started up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that sounds good. I changed the MessengerState to a channel, though I couldn't quite get a oneshot channel to work because it requires a "self" method receiver, which doesn't work for us. So I used a normal mpsc channel instead.

src/lib.rs Outdated Show resolved Hide resolved
@orbitalturtle orbitalturtle force-pushed the send-invoice-req branch 10 times, most recently from d932363 to d64e534 Compare February 2, 2024 07:40
Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Major comments about "readynesss" channel and checking up on whether we can always rely on having an advertised IP (not sure that we can).

src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +49 to +60
pub struct LndkOnionMessenger {
pub offer_handler: OfferHandler,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow the logic of an onion messenger containing an offer handler?
To me the reverse makes more sense: we have an offer handler, and one of the things that it managed is an onion messenger?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess to me it seems like LndkOnionMessenger encompasses any sort of activity dealing with onion messaging, and then offer_handling is a more specific application of onion messaging that we support. And perhaps in the future we might add other applications of onion messaging that might eventually branch off the LndkOnionMessenger struct

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess to me it seems like LndkOnionMessenger encompasses any sort of activity dealing with onion messaging,

That ordering doesn't make sense to me. Sure we may have multiple things using onion messaging one day, but ideally that would just be an abstracted messaging layer that each application interacts with. Maybe I'm missing something, but this layout is analogous to having a top level HTTP struct which has multiple websites inside of it?

Especially with the way that LDK has structured the API for the onion messenger (handlers for different functionality), I think it's far cleaner to have each piece of functionality standalone and referring to the onion messenger. Say we add asynchronous payments, I think that approach 2 here makes way more sense for a modular codebase:

Approach 1:

LndkOnionMessenger{
    OfferHandler,
    AsyncHandler, 
}

vs

Approach 2:

OfferHandler{
    OnionMessenger
}

AsyncHandler{
    OnionMessenger
}

src/lndk_offers.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lndk_offers.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@orbitalturtle orbitalturtle force-pushed the send-invoice-req branch 5 times, most recently from cb6764b to e14f2b4 Compare February 8, 2024 01:34
Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

I'm not fully on board with the architecture chosen here, but I don't want to unnecessarily block on a difference of opinion.

Would be in support of:

  1. Merging the first few commits that have been unchanged for a while
  2. Merging as is (pending small fixups suggested in here) once we have E2E testing paying an offer working and then coming back to refactor

/// otherwise we creae a blinded path directly to ourselves.
pub async fn create_reply_path(
&self,
mut connector: impl PeerConnector + std::marker::Send + 'static,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't need to be 'static?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

without it I get error[E0310]: the parameter type impl MessageSigner + std::marker::Send may not live long enough

And the parameter type impl MessageSigner + std::marker::Send must be valid for the static lifetime...

// Wait for onion messenger to give us the signal that it's ready. Once the onion messenger drops
// the channel sender, recv will return None and we'll stop blocking here.
while (started.recv().await).is_some() {
println!("Error: we shouldn't receive any messages on this channel");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error rather than println?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need a loop here? Can't we just recv().await and then proceed?

if started.recv().await.is_some(){
    return Err(unexpected signal)
}

... continue with logic here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yup good catch, I think that was leftover from when I had put a RefCell in there

@orbitalturtle
Copy link
Collaborator Author

@carlaKC Sounds good, I like option 2. I can see what you're saying above about modularity and I'd be down to switch to your approach. But I like the idea of merging it as is (once we have e2e working, etc), then going back to refactor. Going back and interactive rebasing that big of a change sounds like a royal pain and I'd love to avoid it if possible, ha ha.

carlaKC and others added 24 commits March 6, 2024 15:17
To allow external callers to shutdown lndk, we provide a shutdown
trigger and listener to the onion messenger, replacing the single use
channels that we previously used. This is useful for itests, so that
we can cleanly shut down and for callers of the library to manage
execution.
Provides the end user with something to interact with when they want to
pay offers.
For our integration tests to work properly we need to use a custom version of
lnd's RPC that allows signing the tagged hash (BIP 340) of a message. This was
introduced in LND at commit dacb86f.
For the integration tests to work we need to add the walletrpc subservice to
the lnd make process so we can use the DeriveKey RPC call.
Bumps rust-lightning to a custom version that allows us to sign the invoice
request's tagged hash.
With Rust 1.75.0, we get an unused import error from
configure_me, which we can't change on our end. We ignore this
warning so the CI runs properly.
Before we can send an invoice request, LNDK's onion messenger needs to be fully
started and running. We use a channel close to signal when the messenger is
ready.
We bump ldk-sample to a version that can open channels and broadcasts
the node announcement at a more frequent interval so we can pull ldk's
address from the node graph in our integration tests.
Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Thanks for the quick rebase!

@carlaKC carlaKC merged commit 276c676 into master Mar 7, 2024
4 checks passed
@orbitalturtle orbitalturtle deleted the send-invoice-req branch May 30, 2024 18:02
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.

None yet

2 participants