-
Notifications
You must be signed in to change notification settings - Fork 407
Pre-C bindings cleanups (2) #638
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
Pre-C bindings cleanups (2) #638
Conversation
a85467f
to
b006acb
Compare
Codecov Report
@@ Coverage Diff @@
## master #638 +/- ##
==========================================
- Coverage 91.30% 91.23% -0.08%
==========================================
Files 35 35
Lines 21104 21114 +10
==========================================
- Hits 19270 19263 -7
- Misses 1834 1851 +17
Continue to review full report at Codecov.
|
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.
{ | ||
let funding_txo = monitor.get_funding_txo(); |
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.
Is this scope necessary because of the borrow here?
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.
It is for 1.22, but not for newer versions.
let mut matched_index = Vec::new(); | ||
{ | ||
let watched = self.watched.lock().unwrap(); | ||
for (index, transaction) in block.txdata.iter().enumerate() { | ||
if self.does_match_tx_unguarded(transaction, &watched) { | ||
matched.push(transaction); | ||
matched_index.push(index as u32); |
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.
Keep this as usize
and return Vec<usize>
since you are just casting it back at the call site.
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.
Did so in a new commit since it had a bunch of followon effects.
lightning/src/ln/functional_tests.rs
Outdated
@@ -257,7 +257,7 @@ fn test_update_fee_unordered_raa() { | |||
// ...but before it's delivered, nodes[1] starts to send a payment back to nodes[0]... | |||
let (_, our_payment_hash) = get_payment_preimage_hash!(nodes[0]); | |||
let net_graph_msg_handler = &nodes[1].net_graph_msg_handler; | |||
nodes[1].node.send_payment(&get_route(&nodes[1].node.get_our_node_id(), net_graph_msg_handler, &nodes[0].node.get_our_node_id(), None, &Vec::new(), 40000, TEST_FINAL_CLTV, &logger).unwrap(), our_payment_hash, &None).unwrap(); | |||
nodes[1].node.send_payment(&get_route(&nodes[1].node.get_our_node_id(), &*net_graph_msg_handler.network_graph.read().unwrap(), &nodes[0].node.get_our_node_id(), None, &Vec::new(), 40000, TEST_FINAL_CLTV, &logger).unwrap(), our_payment_hash, &None).unwrap(); |
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.
The dereference is unnecessary here and throughout.
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.
The types are different - without the ref+deref its a MutexGuard, with the ref+deref you get the NetworkGraph itself.
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.
You shouldn't need to explicitly dereference a MutexGuard
. See how it is working correctly in fuzz/src/full_stack.rs
without the dereference.
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.
Actually, not sure if that is the same case, but it does compile here if you remove the dereference.
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.
Ah, I'd tried previously without either the & or *, which obviously doesn't work, but you're right, works with only the &.
912d57a
to
ef57682
Compare
ef57682
to
020ce15
Compare
I did not. Good catch, fixed. |
Looks like a few places in the fuzz code need to be updated for 020ce15. |
795ae9c
to
7741f38
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.
partial 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.
LGTM! Just some nits
lightning/src/ln/channel.rs
Outdated
@@ -3339,6 +3339,11 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> { | |||
channel_id: self.channel_id(), | |||
data: "funding tx had wrong script/value".to_owned() | |||
}); | |||
} else if txo_idx > 0xff_ff { |
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 these checks be tested? or a TODO, or issue to test them?
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.
Oh, oops, duh, funding_txo.index is a u16, so this line is unreachable.
... instead of only the txid. This is another instance of it not being possible to fully re-implement SimpleManyChannelMonitor using only public methods. In this case you couldn't properly register outpoints for monitoring so that the funding transaction would be matched.
In general, we don't need an explicit lifetime when doing something like: fn get_thing(&self) -> &Thing { &self.thing }. This also makes it easier to reason about what's going on in the bindings generation.
This isn't a big difference in the API, but it avoids needing to wrap a given NetworkGraph in a RwLock before passing it, which makes it much easier to generate C bindings for.
This is more consistent with the way we use std::cmp over the codebase and avoids `use std`, which is only actually needed to support older rustcs, so feels a bit awkward.
7741f38
to
8b4c5a3
Compare
non-mut references to primitives are only excess overhead, so there's not much reason to ever have them. As a nice bonus, it also is one less thing to worry about when generating C bindings
Instead of making the filter_block fn in the ChainWatchInterface trait return both a list of indexes of transaction positions within the block and references to the transactions themselves, return only the list of indexes and then build the reference list at the callsite. While this may be slightly less effecient from a memory locality perspective, it shouldn't be materially different. This should make it more practical to generate bindings for filter_block as it no longer needs to reference Rust Transaction objects that are contained in a Rust Block object (which we'd otherwise just pass over the FFI in fully-serialized form).
This was just an oversight when route calculation was split up into parts - it makes no sense for get_route to require that we have a full route message handler, only a network graph (which can always be accessed from a NetGraphMsgHandler anyway).
We use them largely as indexes into a Vec<Transaction> so there's little reason for them to be u32s. Instead, use them as usize everywhere. We also take this opportunity to add range checks before short_channel_id calculation, as we could otherwise end up with a bogus short_channel_id due to an output index out of range.
Squashed. |
8b4c5a3
to
5c37023
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.
Cool, updates LGTM
A second batch of assorted code cleanups that make C binding generation a bit easier. See individual commits for details, but they're all pretty straight forward.