mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-17 03:42:46 +00:00
Move peer db writes to eth2 libp2p (#2724)
## Issue Addressed Part of a bigger effort to make the network globals read only. This moves all writes to the `PeerDB` to the `eth2_libp2p` crate. Limiting writes to the peer manager is a slightly more complicated issue for a next PR, to keep things reviewable. ## Proposed Changes - Make the peers field in the globals a private field. - Allow mutable access to the peers field to `eth2_libp2p` for now. - Add a new network message to update the sync state. Co-authored-by: Age Manning <Age@AgeManning.com>
This commit is contained in:
@@ -236,7 +236,6 @@ impl<T: EthSpec> PeerInfo<T> {
|
||||
/* Mutable Functions */
|
||||
|
||||
/// Updates the sync status. Returns true if the status was changed.
|
||||
// VISIBILITY: Both the peer manager the network sync is able to update the sync state of a peer
|
||||
pub fn update_sync_status(&mut self, sync_status: SyncStatus) -> bool {
|
||||
self.sync_status.update(sync_status)
|
||||
}
|
||||
|
||||
@@ -27,19 +27,6 @@ pub struct SyncInfo {
|
||||
pub finalized_root: Hash256,
|
||||
}
|
||||
|
||||
impl std::cmp::PartialEq for SyncStatus {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
matches!(
|
||||
(self, other),
|
||||
(SyncStatus::Synced { .. }, SyncStatus::Synced { .. })
|
||||
| (SyncStatus::Advanced { .. }, SyncStatus::Advanced { .. })
|
||||
| (SyncStatus::Behind { .. }, SyncStatus::Behind { .. })
|
||||
| (SyncStatus::IrrelevantPeer, SyncStatus::IrrelevantPeer)
|
||||
| (SyncStatus::Unknown, SyncStatus::Unknown)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl SyncStatus {
|
||||
/// Returns true if the peer has advanced knowledge of the chain.
|
||||
pub fn is_advanced(&self) -> bool {
|
||||
@@ -61,7 +48,7 @@ impl SyncStatus {
|
||||
/// E.g. returns `true` if the state changed from `Synced` to `Advanced`, but not if
|
||||
/// the status remained `Synced` with different `SyncInfo` within.
|
||||
pub fn update(&mut self, new_state: SyncStatus) -> bool {
|
||||
let changed_status = *self != new_state;
|
||||
let changed_status = !(self.is_same_kind(&new_state));
|
||||
*self = new_state;
|
||||
changed_status
|
||||
}
|
||||
@@ -75,6 +62,17 @@ impl SyncStatus {
|
||||
SyncStatus::IrrelevantPeer => "Irrelevant",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_same_kind(&self, other: &Self) -> bool {
|
||||
matches!(
|
||||
(self, other),
|
||||
(SyncStatus::Synced { .. }, SyncStatus::Synced { .. })
|
||||
| (SyncStatus::Advanced { .. }, SyncStatus::Advanced { .. })
|
||||
| (SyncStatus::Behind { .. }, SyncStatus::Behind { .. })
|
||||
| (SyncStatus::IrrelevantPeer, SyncStatus::IrrelevantPeer)
|
||||
| (SyncStatus::Unknown, SyncStatus::Unknown)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SyncStatus {
|
||||
|
||||
Reference in New Issue
Block a user