-
Notifications
You must be signed in to change notification settings - Fork 303
Persist name records for Peer Discovery #2529
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
base: master
Are you sure you want to change the base?
Conversation
668c7e3 to
082d149
Compare
eerkaijun
left a comment
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 test plan for this?
| routing_info: self.routing_info.clone(), | ||
| pending_queue: self.pending_queue.clone(), | ||
| }; | ||
| match toml::to_string(&persisted) { |
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.
maybe we can even format to the same format as [[bootstrap.peers]] format, that would probably make it consistent
8e894ef to
4037ac6
Compare
4037ac6 to
d186c76
Compare
| match toml::from_str::< | ||
| BTreeMap<NodeId<CertificateSignaturePubKey<ST>>, MonadNameRecord<ST>>, | ||
| >(&contents) |
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 discussed, is it possible to reuse the struct NodeBootstrapPeerConfig when writing and reading from peers.toml file? so that these name records are recorded in the same format as node.toml
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 it should be pretty straightforward to parse MonadNameRecord into NodeBootstrapPeerConfig, but let me know if that's not the case
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 tried to reuse that struct for serialization but I can't get it to work.
I get "error":"Error { inner: UnsupportedType(None) }" from toml::to_string()
This is an example of a logged persisted struct:
{"message":"persist_peers aggregated routing_info / pending_queue","persisted":"[PersistedPeers { address: \"10.50.37.52:8888\", record_seq_num: 0, secp256k1_pubkey: 02537dd8d905d0e72467fef17fbd1ef5505b1e50993d2be41d3c726d11f750c710, name_record_sig: SecpSignature(RecoverableSignature(574fb64ff66e3d661e303e35618a31a3209b69bfbb93ef13a9ac68eb87cd328a67f2356f28db6ab8745196b2cbc639141d3a72176f66837f533e6a55d1cd2dd901)) }, PersistedPeers { address: \"10.50.37.50:8888\", record_seq_num: 0, secp256k1_pubkey: 0272ac793d36a71739e7080ee5e62029b665aa19a373e7efbc5d28660ad944ab4e, name_record_sig: SecpSignature(RecoverableSignature(f74bd97302961f7c9828963bd5a3394d88d1ac5136004c52c094459537aedf0f2363ad660ca0df738dc77c335e35a519c1049d642fd13cf9e25da393d1ca1fd200)) }]"},"target":"monad_peer_discovery::discovery"}
Attempted method:
fn persist_peers(&self) {
// Persist both routing_info and pending_queue to TOML file
let mut persisted: Vec<PersistedPeers<ST>> = self
.routing_info
.iter()
.map(|(peer_id, name_record)| PersistedPeers {
address: name_record.udp_address().to_string(),
record_seq_num: name_record.seq(),
secp256k1_pubkey: peer_id.pubkey(),
name_record_sig: name_record.signature.clone(),
})
.collect();
for (peer_id, conn_info) in self.pending_queue.iter() {
persisted.push( PersistedPeers {
address: conn_info.name_record.udp_address().to_string(),
record_seq_num: conn_info.name_record.seq(),
secp256k1_pubkey: peer_id.pubkey(),
name_record_sig: conn_info.name_record.signature.clone(),
});
}
match toml::to_string(&persisted) {
Ok(serialized) => {
if let Err(error) = std::fs::write(&self.persisted_peers_path, serialized) {
warn!(path =? self.persisted_peers_path, ?error, "failed to persist peers");
} else {
debug!(path =? self.persisted_peers_path, persisted_len = persisted.len(), "persisted peers to disk");
}
}
Err(error) => {
warn!(path =? self.persisted_peers_path, ?error, "failed to serialize persisted peers");
}
}
| continue; | ||
| } | ||
|
|
||
| match name_record.recover_pubkey() { |
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.
if we use NodeBootstrapPeerConfig to store the entries in peers.toml, we do not need to do recover_pubkey here
| let mut routing_info = self.routing_info.clone(); | ||
| for (peer_id, conn_info) in self.pending_queue.iter() { | ||
| routing_info.insert(*peer_id, conn_info.name_record.clone()); | ||
| } |
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.
we can parse these name records into NodeBootstrapPeerConfig here
| } | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, RlpEncodable, RlpDecodable)] | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, RlpEncodable, RlpDecodable, Deserialize, Serialize)] |
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.
https://github.com/category-labs/monad-bft/pull/2529/files#r2547199504
we wouldn't need Deserialize and Serialize if we do the above
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
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.
same as above
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
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.
same as above
d186c76 to
65bde5e
Compare
| #[serde(deny_unknown_fields)] | ||
| #[serde(bound = "ST: CertificateSignatureRecoverable")] | ||
| pub struct PersistedPeers<ST: CertificateSignatureRecoverable> { | ||
| pub address: String, |
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.
please don't introduce another type that is not future proof.
there is v1 and v2 name record already in the codebase, i think new code should support both of them
| address: name_record.udp_address().to_string(), | ||
| record_seq_num: name_record.seq(), | ||
| secp256k1_pubkey: peer_id.pubkey(), | ||
| name_record_sig: name_record.signature.clone(), |
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.
this is not going to work for v2 record, also it is better to introduce From trait for casts
Related issue:
https://github.com/category-labs/category-internal/issues/1659