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

Add a peer store to network actor #208

Merged
merged 11 commits into from
Oct 23, 2024

Conversation

contrun
Copy link
Collaborator

@contrun contrun commented Sep 27, 2024

Closes #207

assert_eq!(connected_peers.len(), 0);

network_graph.load_from_store();
let connected_peers = network_graph.get_connected_peers();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we change this unit test for PersistentNetworkActorState.
just to make sure the apis work as expected will be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make a unit test for this. The problem now for me is that NetworkActorState is too complex. In order to create a NetworkActorState, we almost certainly need to create a NetworkActor. The pr #205 actually has an easier way to create and restart a network actor. I think that would make the test easier. Admittedly, that is kind of like an integration test. And we still need to solve the problem of how to easily write unit tests for NetworkActorState.

src/fiber/network.rs Outdated Show resolved Hide resolved
src/fiber/network.rs Outdated Show resolved Hide resolved
.store
.get_network_actor_state(&my_peer_id)
.unwrap_or_default();
let mut peers_to_connect = persistent_state.get_peers_to_connect();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any special reason to put persistent_state in NetworkActorState but not in NetworkActor? since in other actors like the ChannelActor, we use a store for persistent storage and ChannelActorState don't have a field for persistent_state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because most fields in the network actor state are volatile, I add a persistent state to make the fact that these fields should be persisted more explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the name PersistentNetworkActorState kind of sucks. It is actually the NetworkActorStateRequiringPersistence.

@@ -3196,6 +3252,9 @@ where
if let Err(err) = state.control.close().await {
error!("Failed to close tentacle service: {}", err);
}
debug!("Saving network actor state for {:?}", state.peer_id);
self.store
.insert_network_actor_state(&state.peer_id, state.persistent_state.clone());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

persistent_state make it confusing since it actually only works like a memory storage, maybe we need to add a store field for persistent_state,
and update the changes into store, so that we can make sure data won't be lost event process is killed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am going to add a store to the persistent_state, then there will be a cyclic dependency chain. The definition of the trait NetworkActorStateStore requires a PersistentNetworkActorState because we have to define what we want to save to/load from the store (this is the struct PersistentNetworkActorState). And the definition of PersistentNetworkActorState contains the field NetworkActorStateStore, hence a dependency cycle. We should do something to ensure that we will not forget to save the state to persistent storage. This is the reason why I wrapped the function save_peer_addresses of PersistentNetworkActorState (which we should not call directly, we can only enforce this by rust's field/methods visibility) to a function save_peer_addresses of NetworkActorState (which does the final persistence work, and we should use this when possible).

@contrun contrun force-pushed the network-actor-connected-peers branch 2 times, most recently from 0eb9ce4 to 1ce1dd7 Compare September 30, 2024 04:04
@contrun contrun force-pushed the network-actor-connected-peers branch 7 times, most recently from 31dd8b3 to 95ce7e7 Compare October 21, 2024 11:36
src/fiber/network.rs Outdated Show resolved Hide resolved
@contrun contrun force-pushed the network-actor-connected-peers branch from 95ce7e7 to d8405d1 Compare October 21, 2024 12:25
@contrun contrun force-pushed the network-actor-connected-peers branch from d8405d1 to a7aac1a Compare October 23, 2024 02:25
@quake quake merged commit 19a57e9 into nervosnetwork:main Oct 23, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bookkeep all the connected peers information in the network actor (instead of network graph)
3 participants