feat/945-persistent-storage-for-peerstore - #946
Conversation
|
@Winter-Soren : Great effort. Reviewing the PR. Re-ran the CI/CD pipeline today after updating the branch. Wish if you could resolve the CI/CD issues. |
…ithub.com/Winter-Soren/py-libp2p into feat/945-persistent-storage-for-peerstore
|
@Winter-Soren : HI Soham. Thank you for resolving the CI/CD issues. 1 CI/CD test is failing. We investigated it and documented it at #949 . @yashksaini-coder , @sumanjeet0012 and @acul71 are fixing it. We will soon have all the CI/CD tests passing. @Winter-Soren : Will re-run CI/CD pipeline once the issue is fixed today or in a couple of days. |
|
Can I get access for this to check and work, @seetadev @Winter-Soren |
Hey @yashksaini-coder, |
|
@Winter-Soren : Updated the branch and re-ran the CI/CD pipeline. There seems to be one test issue. Looking forward to collaborating with you and resolving it soon. |
|
@Winter-Soren : The CI/CD issue got resolved. Wonderful. @pacrob: Hi Paul. Wish to have your feedback on this PR. On the same note, wish to share that I will ask @Winter-Soren and @yashksaini-coder to include a comprehensive test suite and also add a newsfragment. |
|
I added some questions. In this case, I do think example usage would be important. Tests and a newsfragment are also needed here. |
|
Thanks @pacrob for the detailed review and helpful comments 🙏 @Winter-Soren — please take a look at these points and update the PR soon. The switch to Trio (instead of asyncio) is important for consistency with the rest of the lib, so let’s refactor accordingly. Also, make sure the PeerData fields (last_identified, ttl, and latmap) are properly handled so we don’t lose data integrity. Adding a couple of example usages, along with tests and a newsfragment, will round this out nicely and make it easier for others to build on your work. Once you’ve made the updates, tag me and @pacrob for a quick re-review — this is very close to merge-ready! 🚀 |
Thank you so much @acul71 for detailed feedback. Hi @seetadev @pacrob @acul71, |
|
@Winter-Soren : Thank you so much for asking this question. Appreciate it. If the hybrid async/sync approach poses a real risk of data loss or corruption, I’d recommend going with the fully synchronous go-libp2p approach. Reliability should take priority over performance here, unless there’s a strong reason to keep async for throughput. On a similar note, please organize the code in a modular architecture such that if someone wishes to switch from sync to async, they can write the async mechanism and make a switch. This switch should avoid data corruption. Async is important for streaming and high throughput work with webrtc or UDP. |
Optional Dependencies for Persistent PeerstoreThe persistent peerstore implementation supports multiple backend storage engines. While SQLite and in-memory backends work out of the box, LevelDB and RocksDB backends require additional system dependencies that can be challenging to install across different platforms. Supported Backends✅ Always Available
|
… implementations - Updated method signatures in IAsyncAddrBook and IAsyncProtoBook to improve readability by formatting parameters across multiple lines. - Removed unused imports of AsyncGenerator and Coroutine from various files. - Cleaned up whitespace in multiple files to maintain consistency and improve code readability. - Ensured that docstrings remain clear and informative after changes.
…atastore implementations - Updated method signatures in IAsyncCertifiedAddrBook to use Envelope | None for better type clarity. - Cleaned up whitespace in various files, including peerstore and datastore implementations, to enhance code readability. - Simplified iterator usage in LevelDBDatastoreSync to yield directly from the iterator. - Ensured consistent formatting in the __all__ declarations across datastore modules.
- Added type ignore comments for optional imports of plyvel and rocksdb to improve type checking. - Updated the RocksDBDatastoreSync class to include a type ignore comment for the dynamically imported _rocksdb module, ensuring better compatibility with type checkers.
- Updated backoff handling logic in the GossipSub class to always add backoff, regardless of topic presence in the mesh. - Adjusted the wait time in the test_handle_prune function to 0.5 seconds for better compatibility on Windows systems.
PR Review Summary: Persistent Storage for Peerstore #946Summary: ✅ Good Points
❗ Critical Issues (Must Fix)
|
AI Pull Request Review: PR #946 - feat/945-persistent-storage-for-peerstorePR: #946 1. Summary of ChangesThis PR implements persistent storage for py-libp2p's peerstore, addressing issue #945. The implementation enables peer data (addresses, keys, metadata, protocols, latency metrics) to survive process restarts, addressing a critical limitation where all peer information was lost on restart. Key Components Added:
Files Changed:
Breaking Changes:None identified. This is a new feature addition that maintains backward compatibility with existing in-memory peerstore. 2. StrengthsArchitecture & Design
Code Quality
Testing
Documentation
3. Issues FoundCritical3.1 Security: Unsafe Pickle Usage
3.2 Resource Management: Unreliable
|
…ntext managers, and configurable sync
|
Thank you so much @yashksaini-coder and @acul71 for your comprehensive feedback!!! I have successfully addressed ALL the critical feedback. ✅ Original Critical Issues - ALL COMPLETED
✅ Additional Issues Fixed
🔧 Type Checking Issues Resolved
🧪 Testing Status
The persistent peerstore implementation is now production-ready with:
|
…ation modules - Cleaned up whitespace and improved formatting for better readability in example usage of persistent peerstore. - Updated serialization methods to ensure consistent formatting and clarity in the codebase. - Enhanced context manager exit method signatures across various datastore implementations for improved readability.
- Simplified imports for public and private key serialization by removing unnecessary key type mappings. - Improved comments for clarity regarding the limitations of reconstructing PeerRecordState. - Enhanced code readability through consistent formatting and whitespace adjustments.
|
@Winter-Soren : Thank you so much for leading the effort on this PR. Also, wish to thank @yashksaini-coder and @acul71 for their contributions and feedback. @pacrob : Thank you so much for sharing key pointers and improvements with @Winter-Soren earlier while he was working on the PR. He has been able to address them well. Wish to also share that the PR is heading for final review + merge. Wish to have your feedback, recommendations and further improvements @Winter-Soren and @yashksaini-coder need to do in this PR. |
|
@Winter-Soren : Wish if you could share your implementation approach and important takeaways, notes on the recent updates in this PR on a discussion page. |
|
The following is a very light review of integrating peerstore. I've done minimal testing. There's a few issues I think exist with persistent peerstore when integrating it: Note: This isn't an issue with persistent peerstore, only using it. Swam class:
|
What was wrong?
Currently, py-libp2p only provides an in-memory peerstore implementation that loses all peer data (addresses, keys, metadata, protocols) when the process restarts. This limits the resilience and performance of py-libp2p nodes, especially for long-running applications that need to maintain peer information across restarts.
Issue #945
How was it fixed?
Implemented a datastore-agnostic persistent peer storage system following the same architectural pattern as go-libp2p's
pstoredspackage. The solution provides:Summary of approach
Core Components:
libp2p/peer/datastore/): Pluggable interface supporting multiple backendslibp2p/peer/persistent_peerstore.py): Full async implementation with memory cachinglibp2p/peer/persistent_peerstore_factory.py): Convenient creation methodsSupported Backends:
To-Do
Cute Animal Picture