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

@@ -213,14 +213,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
match self.state() {
BackFillState::Syncing => {} // already syncing ignore.
BackFillState::Paused => {
if self
.network_globals
.peers
.read()
.synced_peers()
.next()
.is_some()
{
if self.network_globals.peers().synced_peers().next().is_some() {
// If there are peers to resume with, begin the resume.
debug!(self.log, "Resuming backfill sync"; "start_epoch" => self.current_start, "awaiting_batches" => self.batches.len(), "processing_target" => self.processing_target);
self.set_state(BackFillState::Syncing);
@@ -906,8 +899,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
let new_peer = {
let mut priorized_peers = self
.network_globals
.peers
.read()
.peers()
.synced_peers()
.map(|peer| {
(
@@ -1026,8 +1018,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
let mut rng = rand::thread_rng();
let mut idle_peers = self
.network_globals
.peers
.read()
.peers()
.synced_peers()
.filter(|peer_id| {
self.active_requests