Skip to content
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

Remove persistence of PeerStore to DB #8617

Merged
merged 12 commits into from
Feb 23, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ to pay for the storage of their accounts.
* `ClientConfig` can be updated while the node is running.
`dyn_config.json` is no longer needed as its contents were merged into `config.json`.
[#8240](https://github.com/near/nearcore/pull/8240)
* TIER2 network stabilization. Long-lasting active connections are persisted to DB and are re-established automatically if either node restarts. A new neard flag `--connect-to-reliable-peers-on-startup` is provided to toggle this behavior; it defaults to true. The PeerStore is no longer persisted to DB and is now kept in-memory. [#8579](https://github.com/near/nearcore/issues/8579), [#8580](https://github.com/near/nearcore/issues/8580).

## 1.31.0

Expand Down
2 changes: 1 addition & 1 deletion chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,7 @@ impl<'a> ChainStoreUpdate<'a> {
| DBCol::BlockMisc
| DBCol::_GCCount
| DBCol::BlockHeight // block sync needs it + genesis should be accessible
| DBCol::Peers
| DBCol::_Peers
| DBCol::RecentOutboundConnections
| DBCol::BlockMerkleTree
| DBCol::AccountAnnouncements
Expand Down
1 change: 0 additions & 1 deletion chain/network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub use crate::peer_manager::peer_manager_actor::{Event, PeerManagerActor};
pub use crate::peer_manager::peer_store::iter_peers_from_store;

mod accounts_data;
mod network_protocol;
Expand Down
12 changes: 3 additions & 9 deletions chain/network/src/peer/peer_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,7 @@ impl PeerActor {
}
HandshakeFailureReason::InvalidTarget => {
tracing::debug!(target: "network", "Peer found was not what expected. Updating peer info with {:?}", peer_info);
if let Err(err) =
self.network_state.peer_store.add_direct_peer(&self.clock, peer_info)
{
tracing::error!(target: "network", ?err, "Fail to update peer store");
}
self.network_state.peer_store.add_direct_peer(&self.clock, peer_info);
self.stop(ctx, ClosingReason::HandshakeFailed);
}
}
Expand Down Expand Up @@ -1133,12 +1129,10 @@ impl PeerActor {
PeerMessage::PeersResponse(peers) => {
tracing::debug!(target: "network", "Received peers from {}: {} peers.", self.peer_info, peers.len());
let node_id = self.network_state.config.node_id();
if let Err(err) = self.network_state.peer_store.add_indirect_peers(
self.network_state.peer_store.add_indirect_peers(
&self.clock,
peers.into_iter().filter(|peer_info| peer_info.id != node_id),
) {
tracing::error!(target: "network", ?err, "Fail to update peer store");
};
);
self.network_state
.config
.event_sink
Expand Down
3 changes: 1 addition & 2 deletions chain/network/src/peer/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ impl PeerHandle {
let network_state = Arc::new(NetworkState::new(
&clock,
store.clone(),
peer_store::PeerStore::new(&clock, network_cfg.peer_store.clone(), store.clone())
.unwrap(),
peer_store::PeerStore::new(&clock, network_cfg.peer_store.clone()).unwrap(),
network_cfg.verify().unwrap(),
cfg.chain.genesis_id.clone(),
fc.clone(),
Expand Down
6 changes: 2 additions & 4 deletions chain/network/src/peer_manager/network_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,8 @@ impl NetworkState {
.await
.map_err(|_: ReasonForBan| RegisterPeerError::InvalidEdge)?;
this.tier2.insert_ready(conn.clone()).map_err(RegisterPeerError::PoolError)?;
// Best effort write to DB.
if let Err(err) = this.peer_store.peer_connected(&clock, peer_info) {
tracing::error!(target: "network", ?err, "Failed to save peer data");
}
// Write to the peer store
this.peer_store.peer_connected(&clock, peer_info);
}
}
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions chain/network/src/peer_manager/peer_manager_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ impl PeerManagerActor {
) -> anyhow::Result<actix::Addr<Self>> {
let config = config.verify().context("config")?;
let store = store::Store::from(store);
let peer_store =
peer_store::PeerStore::new(&clock, config.peer_store.clone(), store.clone())
.context("PeerStore::new")?;
let peer_store = peer_store::PeerStore::new(&clock, config.peer_store.clone())
.context("PeerStore::new")?;
tracing::debug!(target: "network",
len = peer_store.len(),
boot_nodes = config.peer_store.boot_nodes.len(),
Expand Down
Loading