-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor/peer persistence #327
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: refactor/storage-manager-trait
Are you sure you want to change the base?
Refactor/peer persistence #327
Conversation
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis PR refactors the storage architecture from a monolithic DiskStorageManager to a modular design with specialized storage traits (BlockHeaderStorage, FilterHeaderStorage, ChainStateStorage, etc.). Sync and client code is updated to read state from storage rather than in-memory state. The peer persistence layer is restructured, and related tests are updated for new APIs. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SyncMgr as SyncManager
participant HeaderSync
participant Storage
participant Disk
rect rgb(200, 220, 240)
Note over Client,Disk: Old Flow: In-Memory State
Client->>SyncMgr: load_headers_from_storage()
SyncMgr->>SyncMgr: Read chain_state.tip_height (in-memory)
SyncMgr->>SyncMgr: Return count of synced headers
SyncMgr->>Client: Result<u32>
end
rect rgb(240, 220, 200)
Note over Client,Disk: New Flow: Storage-Backed State
Client->>SyncMgr: load_headers_from_storage(storage)
SyncMgr->>HeaderSync: load_headers_from_storage(storage)
HeaderSync->>Storage: get_tip_height().await
Storage->>Disk: Read persisted header state
Disk-->>Storage: Option<u32>
Storage-->>HeaderSync: Option<u32>
HeaderSync->>HeaderSync: Load headers from storage via BlockHeaderStorage
HeaderSync-->>SyncMgr: (void)
SyncMgr-->>Client: (void)
end
sequenceDiagram
participant SyncMgr as Sync Flow
participant NetMgr as NetworkManager
participant Storage
participant PeerStor as PeerStorage
rect rgb(200, 240, 220)
Note over SyncMgr,PeerStor: Old Peer Persistence
NetMgr->>NetMgr: Load PeerStore from file path
NetMgr->>NetMgr: Read peers.dat, reputations.json (file I/O)
NetMgr->>NetMgr: Manage reputation in-memory
NetMgr->>NetMgr: Save reputation back to file
end
rect rgb(240, 240, 200)
Note over SyncMgr,PeerStor: New Peer Persistence (Storage-Backed)
NetMgr->>Storage: PersistentPeerStorage::open(path)
Storage->>PeerStor: Initialize storage layer
NetMgr->>Storage: load_peers() via PeerStorage trait
Storage->>PeerStor: Read from peers.dat
PeerStor-->>Storage: Vec<SocketAddr>
Storage-->>NetMgr: Vec<SocketAddr>
NetMgr->>Storage: load_peers_reputation() via PeerStorage
Storage->>PeerStor: Deserialize reputations.json
PeerStor-->>Storage: HashMap<SocketAddr, PeerReputation>
Storage-->>NetMgr: HashMap (with validation & clamping)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5d78f43 to
2d4550e
Compare
The peers and peers reputation storage logic moved into the storage module following the trait pattern introduced by PR #311. Also moved PeerReputation values validation logic into serde's pipeline
This PR is built on top of #311
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.