Skip to content

Serialize ChannelManager events #617

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

Conversation

sourabhmarathe
Copy link
Contributor

Addresses issue #538

@codecov
Copy link

codecov bot commented May 7, 2020

Codecov Report

Merging #617 into master will increase coverage by 0.04%.
The diff coverage is 97.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #617      +/-   ##
==========================================
+ Coverage   91.19%   91.24%   +0.04%     
==========================================
  Files          35       35              
  Lines       20693    20787      +94     
==========================================
+ Hits        18872    18967      +95     
+ Misses       1821     1820       -1     
Impacted Files Coverage Δ
lightning/src/ln/channelmanager.rs 85.52% <93.33%> (+0.02%) ⬆️
lightning/src/ln/functional_tests.rs 97.10% <98.79%> (-0.08%) ⬇️
lightning/src/util/events.rs 29.03% <0.00%> (+8.60%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5723c7...9c587e5. Read the comment docs.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Thanks, looking good! First of all, note that your editor seems confused and the indentation is off in a few places. You should use tabs to match existing indentation.

More importantly, it would be great to get a test for, eg, FundingBroadcstSafe here (mostly because I'm not sure if those already are regenerated on load). You can probably copy/extend one of the serialize_deserialize tests in src/ln/functional_tests, eg test_simple_manager_serialize_deserialize() as a starting point. Then just add eg partial channel open by replacing the call to create_announced_chan_between_nodes with its constituent parts (most of our test utils just call other test utils, in this case you probably want to call through create_chan_between_nodes_with_value_a and then check that you can call create_chan_between_nodes_with_value_b after the reload, or something like that.

@sourabhmarathe sourabhmarathe marked this pull request as ready for review May 8, 2020 21:58
Copy link
Contributor

@valentinewallace valentinewallace 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 PR & for adding the test! :)

@sourabhmarathe
Copy link
Contributor Author

Thanks for the comments! I got the changes in, and this PR should be ready for another look.

@TheBlueMatt
Copy link
Collaborator

I did notice for the other fields, the cmp::min is either the count variable or a hard coded 128 value. Should I create that variable let MAX_ALLOC_SIZE: u64 = 54*1024; and then use that for the other values being read in as well?

Yep, totally! The old ones were just the math done manually, but there's no reason for that and its less clear.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Test looks great! good job on that. One nit and one note, but otherwise ready to go. If you feel like changing all the other deserialization with_capacity() calls, feel free, otherwise it can be done at some point in the future.

@sourabhmarathe
Copy link
Contributor Author

Test looks great! good job on that. One nit and one note, but otherwise ready to go. If you feel like changing all the other deserialization with_capacity() calls, feel free, otherwise it can be done at some point in the future.

I took care of it, I believe I mapped over what was was done for events to the other types properly, but you may want to confirm that. Otherwise, got the PR up to date with master.

@sourabhmarathe sourabhmarathe force-pushed the serialize-channelmanager-events branch from e9362db to 06b9927 Compare May 13, 2020 21:42
let forward_htlcs_count: u64 = Readable::read(reader)?;
let mut forward_htlcs = HashMap::with_capacity(cmp::min(forward_htlcs_count as usize, 128));
let mut forward_htlcs = HashMap::with_capacity(cmp::min(forward_htlcs_count as usize, (MAX_ALLOC_SIZE as usize)/mem::size_of::<HTLCForwardInfo>()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, the inner in the hashmap isn't a HTLCForwardInfo, its a (u64, Vec<_>). The HTLCForwardInfo-relevant line is four lines down when we allocate the Vec::with_capacity(). The same goes for claimable_htlcs below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed forward_htlcs and claimable_htlcs (put them back to 128) and for per_peer_state's size, used its type: <RwLock<HashMap<PublicKey, Mutex<PeerState>>>> for the denominator under MAX_ALLOC_SIZE

Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of RwLock<HashMap<PublicKey, Mutex<PeerState>>>, you probably want (PublicKey, Mutex<PeerState>).

The goal here is to capture that we only ever want to allocate up to 64KB for internal contents at a time - in a Vec the internal, heap-allocated things are of type X (where the vec is Vec). In a HashMap, the internal contents are usually (K, V) (where its a HashMap<K, V>), though I don't think Rust guarantees this, its close enough for our purposes, it doesn't have to be exact. We always allocate the RwLock<HashMap<>> data on the stack, so its not the variable part, its the number of (K, V) entries that is the variable part.

@sourabhmarathe sourabhmarathe force-pushed the serialize-channelmanager-events branch from 6aae3dc to 056e1b0 Compare May 14, 2020 09:58
Also adds a test for de/serializing events
@sourabhmarathe sourabhmarathe force-pushed the serialize-channelmanager-events branch from 4f410d5 to 9c587e5 Compare May 14, 2020 21:03
@TheBlueMatt TheBlueMatt merged commit 59fe300 into lightningdevkit:master May 14, 2020
@sourabhmarathe sourabhmarathe deleted the serialize-channelmanager-events branch May 15, 2020 00:40
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.

3 participants