-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Refactor pchain network engine #15
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
Conversation
src/behaviour.rs
Outdated
| .max_transmit_size(MAX_TRANSMIT_SIZE * MEGABYTES) // block size is limitted to 2 MB. Multiply by factor of safety = 2. | ||
| .message_id_fn(build_msg_id) | ||
| .heartbeat_interval(Duration::from_secs(heartbeat_secs)) | ||
| .heartbeat_interval(Duration::from_secs(10)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can take this magic number out and put them with the constant up there. (Not a must, just think it might be cleaner)
src/behaviour.rs
Outdated
|
|
||
| pub(crate) const MAX_TRANSMIT_SIZE: usize = 4; | ||
| pub(crate) const MEGABYTES: usize = 1048576; | ||
| pub(crate) const PROTOCOL_NAME: &str = "/pchain_p2p/1.0.0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Protocol name is no longer a constant, it is a field in Config. That's on me, I forgot to remove it from constant.rs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both identity config and kademlia config uses protocol name, however, while kademlia accepts multiple names, identity accepts only 1. So in the event we have multiple protocol names, which one do we use for identity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in our Config, we can change the protocol name into a single String instead of a Vec, just like what we used to do. Only put it into a vector in Kad config.
src/engine.rs
Outdated
| &local_keypair, | ||
| 10, | ||
| &config.kademlia_protocol_names, //TODO jonas | ||
| &local_keypair |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned previously, protocol name is no longer a constant, its a configurable field in Config, so we might have to pass in the Config instance.
src/engine.rs
Outdated
| // TryFrom trait for Vec<u8> to Message, implement a function that takes in the Message Topic to help | ||
| // converting Vec<u8> to Message. You can refer to fullnode/mempool messagegate to see how to | ||
| // deserialise each Message type. | ||
| match message.topic.as_str() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you couldn't do branches like Topic::Mempool.hash() in match statement. But comparing the topic using string doesn't seem a good idea.
let topic = fullnode_topics(public_addr).into_iter().find(|t| t.hash() == message.topic);
Will this way of identifying the topic work? I haven't verified, you can try.
…nd heartbeat interval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments on the functions for deserializing Vec to pchain_network::message::Message
src/engine.rs
Outdated
| // 3. Subscribe to Topic | ||
| //TODO jonas | ||
| swarm.behaviour_mut().subscribe()?; | ||
| swarm.behaviour_mut().subscribe(config::fullnode_topics(local_public_address))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think all applications that uses pchain_network will always subscribe to all topics. For example, fullnode doesn't subscribe to droppedTx. So the topics to be subscribed should be based on the Config we passed in.
src/engine.rs
Outdated
| match topic { | ||
| HotStuffRsBroadcast => { | ||
| let hotstuff_message = | ||
| hotstuff_rs::messages::Message::deserialize(&mut message.data.as_slice()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason of getting the de-serialized result of type Result<> and wrap them with Optional and check if it is Some() or None later? Can't we do something directly when the deserialisation gives out Error?
Also, you gotta return the deserialised message out after this match statement. You should be about to return pchain_network::message::Message.
You might consider getting this part out into a separate helper function to make it look cleaner.
|
I have completed the changes according to your suggestions, but i still think we should match to the topic hash instead of topic. The conditional function below checks whether the local peer is subscribed to the message's topic hash. And after checking, we repeat the check just to get the Topic type. Additionally, |
|
I understand the problem you mentioned, but not really clear about your solution. Have you implemented your thoughts in the recent commit? If not, please do it the way you think it works, doesn't have to follow my suggestions 100%. |
|
the current implementation works for v0.5, will work on my solution for future updates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolve the conflicts then this branch will be ready to be merged.
Changes
network subscribes to
Vec<Topic>fromconfig::fullnode_topics(local_public_address)instead of being a separate argument tostartMessage types are determined via
message.topic.as_str()which can be matched to: "consensus", "mempool" , "droppedTx" and public address string. The message data can then be deserialised according to the type of message it is:hotstuff_rs::messages::Messagepchain_types::blockchain::TransactionV1DroppedTxMessageconstant inputs like protocol name and heartbeat seconds were being passed as arguments to
Behaviour::new()which were subsequently passed as arguments tokad_config()andgossipsub_config. Removed these redundant arguments and used them in the lowest level functions instead.