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

refactor(gossip) Add methods, data structures, and edits to improve memory safety in gossip #189

Merged
merged 20 commits into from
Jul 15, 2024

Conversation

yewman
Copy link
Contributor

@yewman yewman commented Jul 5, 2024

Memory Leaks

  • Found a few more memory leaks while thinking about clone / deinit implementation.
  • Implemented basic fix - call bincode.free
  • Ideally should add test cases for unhappy paths

ThreadSafeContactInfo

  • In a number of places, ContactInfo was being passed around outside of lock boundaries for purposes not requiring access to the heap memory contained within. Whilst these usages were not causing any errors, creating and using an explicitly thread safe type seems like a good idea as makes the code more robust, simpler to understand, and easier to debug.

Clone

  • Implement clone methods for instances where we need access to the heap allocated memory of gossip values outside of a table lock scope.

Other

  • Add saturating subs for timestamp operations
  • Remove parameter to processMessages - no need to parse a parameter which is contained in self

@yewman yewman changed the title refactor(gossip): Add methods, data structures, and edits to improve memory safety in gossip refactor(gossip) WIP: Add methods, data structures, and edits to improve memory safety in gossip Jul 5, 2024
Copy link
Contributor

@InKryption InKryption left a comment

Choose a reason for hiding this comment

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

Just a few notes, otherwise LGTM.

src/accountsdb/download.zig Outdated Show resolved Hide resolved
src/gossip/ping_pong.zig Show resolved Hide resolved
src/gossip/ping_pong.zig Show resolved Hide resolved
@InKryption
Copy link
Contributor

InKryption commented Jul 5, 2024

Th failing CI is due to #157.
Edit: I re-ran the job, so it shouldn't fail unless we're particularly unlucky with entropy.

src/accountsdb/download.zig Show resolved Hide resolved
src/gossip/table.zig Outdated Show resolved Hide resolved
src/gossip/ping_pong.zig Show resolved Hide resolved
src/gossip/service.zig Outdated Show resolved Hide resolved
src/gossip/service.zig Outdated Show resolved Hide resolved
src/gossip/service.zig Outdated Show resolved Hide resolved
@yewman yewman force-pushed the harnew/gossip-safety branch 2 times, most recently from b7d92fa to 24b8ac4 Compare July 9, 2024 19:52
@yewman yewman changed the title refactor(gossip) WIP: Add methods, data structures, and edits to improve memory safety in gossip refactor(gossip) Add methods, data structures, and edits to improve memory safety in gossip Jul 10, 2024
@yewman yewman requested a review from 0xNineteen July 10, 2024 20:43
Copy link
Contributor

@0xNineteen 0xNineteen left a comment

Choose a reason for hiding this comment

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

lgtm - should be good to merge after you add the docs

@yewman yewman requested a review from 0xNineteen July 11, 2024 17:27
0xNineteen
0xNineteen previously approved these changes Jul 11, 2024
Copy link
Contributor

@0xNineteen 0xNineteen left a comment

Choose a reason for hiding this comment

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

lgtm - should get @dnut approval too since he has a lot of context around this problem

@0xNineteen 0xNineteen requested a review from dnut July 11, 2024 18:30
@yewman yewman requested a review from 0xNineteen July 11, 2024 22:20
Copy link
Contributor

@dnut dnut left a comment

Choose a reason for hiding this comment

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

Looks good, I just have a few minor concerns.

I like the approach of just returning a lean contact info with the bare minimum data, instead of requiring more allocations. It actually moves us back away from the new ContactInfo, closer towards something resembling LegacyContactInfo. If we go all-in on this approach, at some point we could probably get rid of the contact info mapping that I added to facilitate the migration to ContactInfo.

converted_contact_infos: AutoArrayHashMap(Pubkey, ContactInfo),

I can imagine some approaches where a caller could specify exactly the minimum amount of data they need about a contact. Something that feels like graphql.

src/gossip/table.zig Show resolved Hide resolved
src/gossip/service.zig Outdated Show resolved Hide resolved
src/gossip/service.zig Show resolved Hide resolved
src/gossip/service.zig Show resolved Hide resolved
@yewman yewman requested review from dnut and InKryption July 15, 2024 18:03
Copy link
Contributor

@InKryption InKryption left a comment

Choose a reason for hiding this comment

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

Need to go over some details concerning bincode.

src/bincode/bincode.zig Outdated Show resolved Hide resolved
0xNineteen
0xNineteen previously approved these changes Jul 15, 2024
@0xNineteen 0xNineteen merged commit 7bb6345 into main Jul 15, 2024
5 checks passed
@0xNineteen 0xNineteen deleted the harnew/gossip-safety branch July 15, 2024 21:19
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.

4 participants