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:
Divma
2021-11-19 04:42:31 +00:00
parent 31386277c3
commit 53562010ec
16 changed files with 139 additions and 154 deletions

View File

@@ -17,7 +17,7 @@ use lighthouse_network::{
types::{GossipEncoding, GossipTopic},
BehaviourEvent, MessageId, NetworkGlobals, PeerId,
};
use lighthouse_network::{MessageAcceptance, Service as LibP2PService};
use lighthouse_network::{MessageAcceptance, Service as LibP2PService, SyncStatus};
use slog::{crit, debug, error, info, o, trace, warn};
use std::{net::SocketAddr, pin::Pin, sync::Arc, time::Duration};
use store::HotColdDB;
@@ -100,6 +100,10 @@ pub enum NetworkMessage<T: EthSpec> {
reason: GoodbyeReason,
source: ReportSource,
},
UpdatePeerSyncStatus {
peer_id: PeerId,
sync_status: SyncStatus,
},
}
/// Service that handles communication between internal services and the `lighthouse_network` network service.
@@ -527,6 +531,9 @@ fn spawn_service<T: BeaconChainTypes>(
);
}
}
NetworkMessage::UpdatePeerSyncStatus{peer_id, sync_status} => {
service.libp2p.swarm.behaviour_mut().update_peers_sync_status(&peer_id, sync_status);
}
}
}
// process any attestation service events