Skip to content

Conversation

@fabiotdf
Copy link

@fabiotdf fabiotdf commented Nov 6, 2025

@fabiotdf fabiotdf requested a review from eerkaijun November 6, 2025 21:54
@fabiotdf fabiotdf force-pushed the fabio/pers_name_recs branch from 668c7e3 to 082d149 Compare November 6, 2025 21:55
Copy link
Contributor

@eerkaijun eerkaijun left a 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) {
Copy link
Contributor

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

@fabiotdf fabiotdf force-pushed the fabio/pers_name_recs branch 2 times, most recently from 8e894ef to 4037ac6 Compare November 9, 2025 23:32
@fabiotdf fabiotdf force-pushed the fabio/pers_name_recs branch from 4037ac6 to d186c76 Compare November 20, 2025 17:44
Comment on lines 279 to 281
match toml::from_str::<
BTreeMap<NodeId<CertificateSignaturePubKey<ST>>, MonadNameRecord<ST>>,
>(&contents)
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Author

@fabiotdf fabiotdf Nov 21, 2025

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() {
Copy link
Contributor

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

Comment on lines 670 to 673
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());
}
Copy link
Contributor

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)]
Copy link
Contributor

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)]
Copy link
Contributor

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)]
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

@fabiotdf fabiotdf force-pushed the fabio/pers_name_recs branch from d186c76 to 65bde5e Compare November 20, 2025 19:04
#[serde(deny_unknown_fields)]
#[serde(bound = "ST: CertificateSignatureRecoverable")]
pub struct PersistedPeers<ST: CertificateSignatureRecoverable> {
pub address: String,
Copy link
Contributor

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(),
Copy link
Contributor

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

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.

5 participants