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

Update to LDK 0.1-beta1 #137

Merged
merged 6 commits into from
Feb 25, 2025
Merged

Update to LDK 0.1-beta1 #137

merged 6 commits into from
Feb 25, 2025

Conversation

TheBlueMatt
Copy link
Contributor

No description provided.

@TheBlueMatt TheBlueMatt force-pushed the main branch 4 times, most recently from 76cc0a2 to 04aaa24 Compare January 13, 2025 15:38
@TheBlueMatt
Copy link
Contributor Author

Need to switch to using the new inbound payment paymentid.

@TheBlueMatt TheBlueMatt force-pushed the main branch 2 times, most recently from 2b42d4f to fa96ed2 Compare January 13, 2025 20:10
@@ -226,10 +235,42 @@ impl BitcoindClient {
});
}

fn run_future_in_blocking_context<F: Future + Send + 'static>(&self, future: F) -> F::Output
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, given this is the sample I don't think we'd want to advise users to employ such hacky manners? Instead, can we just switch to a pattern that avoids block_on altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what alternative we have? I'm not aware of another option.

Copy link
Contributor

@tnull tnull Jan 15, 2025

Choose a reason for hiding this comment

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

I'm not sure what alternative we have? I'm not aware of another option.

I think there are a bunch of options, but one would to create an actor that is driven by a task spawned upon intialization. Then any of these blocking trait calls could communicate with that actor via MPSC channels, for example. This should work and would keep the blocking and async contexts more or less separate, no?
(although we might still run into issues when, depending on the actual callstack, we'd block the current thread, as other tasks might still try to run on the same runtime thread, IIUC. But that seems like an orthogonal issue we can't really resolve until we have proper async support/traits throughout the codebase, AFAICT).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there are a bunch of options, but one would to create an actor that is driven by a task spawned upon intialization. Then any of these blocking trait calls could communicate with that actor via MPSC channels, for example. This should work and would keep the blocking and async contexts more or less separate, no?

I don't believe the net-impact of that is any different than what we're already doing by spawning the task on a background task at the time we need it.

But that seems like an orthogonal issue we can't really resolve until we have proper async support/traits throughout the codebase, AFAICT

It looks like the only use of the sync->async inversion in the current ldk-sample codebase is in the anchor spend paths (ChangeDestinationSource+WalletSource) so it may be practical to make that whole thing dual-sync-async upstream pretty easily (with some proc macro, I assume)?

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the only use of the sync->async inversion in the current ldk-sample codebase is in the anchor spend paths (ChangeDestinationSource+WalletSource) so it may be practical to make that whole thing dual-sync-async upstream pretty easily (with some proc macro, I assume)?

I'm not quite sure this is true, due to ChangeDestinationSource being used in OutputSweeper's spending method which in turn is triggered by Confirm/Listen. So if we make the traits async-optional, we'd also need to propagate it up the chain syncing logic, including all the traits and connected methods, no? But let's probably continue this discussion on lightningdevkit/rust-lightning#3540.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grrrrr

@TheBlueMatt TheBlueMatt force-pushed the main branch 2 times, most recently from f7eb75b to 21f12a5 Compare January 14, 2025 15:42
// part of a tokio runtime (which in this case it is - the main tokio runtime). Thus, we
// have to `spawn` the `future` on the secondary runtime and then `block_on` the resulting
// `JoinHandle` on the main runtime.
tokio::task::block_in_place(move || {
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, note that this block_in_place will act on whatever runtime context is present here. This might or might not be the main runtime, it also could result being a no-op.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I think all of that is fine? Its generally expected to be the main runtime, but the point is just to tell the runtime "hey, this is gonna take some time, go ahead and make sure there's another thread to run actually-async things". Its just opportunistic, but we don't rely on it - we'll eventually return and the runtime will be happy.

This used to be disabled at compile-time, but the feature was
removed as it didn't net substantial performance gain, so now we
disable them at runtime.
See the comment in the commit for more info on why we have to do
this.
@TheBlueMatt
Copy link
Contributor Author

Need to switch to using the new inbound payment paymentid.

Actually doesn't make sense since we track payments since invoice creation, so need to index by payment hash.

Updated to 0.1 release, this should be good to go!

@tnull
Copy link
Contributor

tnull commented Jan 17, 2025

Actually doesn't make sense since we track payments since invoice creation, so need to index by payment hash.

Hmm, well, but it might be a good point in time to actually change that as it's kind of weird to have a behavioral difference between BOLT11 and BOLT12 here? FWIW, we have the same issue in LDK Node, but there we'll only be able to remedy it via introducing a new metadata store holding on to offers and invoices (cf. lightningdevkit/ldk-node#425).

@TheBlueMatt
Copy link
Contributor Author

Good idea, added HRN support.

@TheBlueMatt
Copy link
Contributor Author

Hmm, well, but it might be a good point in time to actually change that as it's kind of weird to have a behavioral difference between BOLT11 and BOLT12 here? FWIW, we have the same issue in LDK Node, but there we'll only be able to remedy it via introducing a new metadata store holding on to offers and invoices (cf. lightningdevkit/ldk-node#425).

Yea, we probably should eventually change the inbound payment store here to associate OfferIds with the inbound payment, but that's a bigger overhaul and we can do it another time, I think.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

LGTM

Discussed offline to accept the last commit as a temporary workaround, but that we will see to ship a proper fix (async traits) in LDK 0.2

@tnull tnull merged commit 664f6c4 into lightningdevkit:main Feb 25, 2025
4 checks passed
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