-
Notifications
You must be signed in to change notification settings - Fork 113
Add onion mailbox for async recipients #632
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
base: develop
Are you sure you want to change the base?
Conversation
👋 Thanks for assigning @tnull as a reviewer! |
996d102
to
f70cd08
Compare
8612c01
to
d9545a8
Compare
9818d0c
to
89d74d5
Compare
src/lib.rs
Outdated
} | ||
|
||
#[allow(missing_docs)] | ||
pub fn om_mailbox_is_empty(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to expose this to the integration test, but not sure how to do it without introducing an extra cfg flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's why they are integration / black box tests, they test the public API. Would be good to drop this method. If you want to test internal functionality, you'd need to write a unit test.
There was a problem hiding this comment.
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 is so binary, but I understand your pov. As far as I know, there isn't really another way to detect that the onion message is intercepted and waiting. Would you want to use a (blind) sleep instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using sleep 3s now.
🔔 1st Reminder Hey @tnull! This PR has been waiting for your review. |
🔔 2nd Reminder Hey @tnull! This PR has been waiting for your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rebase now.
8192f71
to
a971ee4
Compare
Rebased after merge of #621 |
a654b4e
to
2cac461
Compare
2cac461
to
ce98969
Compare
ce98969
to
d874141
Compare
Updated to latest version of lightningdevkit/rust-lightning#4046 |
src/event.rs
Outdated
LdkEvent::OnionMessageIntercepted { .. } => { | ||
debug_assert!(false, "We currently don't support onion message interception, so this event should never be emitted."); | ||
LdkEvent::OnionMessageIntercepted { peer_node_id, message } => { | ||
self.om_mailbox.onion_message_intercepted(peer_node_id, message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still log an error and do nothing here if !config.async_payment_services_enabled
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added trace log
src/builder.rs
Outdated
}, | ||
}; | ||
|
||
let om_mailbox = Arc::new(OnionMessageMailbox::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this an Option
that will only be set if async_payment_services_enabled
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a fan of this type of optionality as there resources involved with an empty onion mailbox are negligible. But made the change.
src/lib.rs
Outdated
} | ||
|
||
#[allow(missing_docs)] | ||
pub fn om_mailbox_is_empty(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's why they are integration / black box tests, they test the public API. Would be good to drop this method. If you want to test internal functionality, you'd need to write a unit test.
src/om_mailbox.rs
Outdated
} | ||
|
||
impl OnionMessageMailbox { | ||
const MAX_MESSAGES_PER_PEER: usize = 100; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, these 100/100 values seems relatively restrictive and still results in ~300 MB of OM data in memory, AFAIU.
Maybe it would be worth to at least go for a 30/300 ratio, so that we allow for more potential peers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any of those constant can be right or wrong, no strong opinion about it. Changed.
src/om_mailbox.rs
Outdated
let peer_to_remove = map | ||
.iter() | ||
.max_by_key(|(_, queue)| queue.len()) | ||
.map(|(peer, _)| peer.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think PublicKey
is Copy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Made it *peer
src/om_mailbox.rs
Outdated
const MAX_PEERS: usize = 100; | ||
|
||
pub fn new() -> Self { | ||
Self { map: Mutex::new(HashMap::new()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to pre-alloc some capacity
from the start to avoid constant reallocations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is triggered by a network message, this seems to be a negligible optimization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added MAX_PEERS capacity.
cfc9387
to
39fe521
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs yet another rebase now
39fe521
to
6ac6ab6
Compare
This introduces an in-memory mailbox to hold onion messages until the receiver comes online. This is required for async payment `held_htlc_available` messages. The mailbox is bounded by a maximum number of peers and a maximum number of messages per peer.
6ac6ab6
to
7a1ad85
Compare
Rebased |
Adds functionality for LSPs to hold onion messages for their clients until they come back online.
Depends on lightningdevkit/rust-lightning#4046