Skip to content

Store PeerKind in known-peers file #15765

Open
@mattsse

Description

@mattsse

Describe the feature

currently on shutdown we store just the enodes:

match network.write_peers_to_file(peers_file.as_path()) {

thereby stripping away context, such as whether the peer is trusted or not.

TODO

  • introduce a new datastructure that also groups them by PeerKind in the file
  • update read and write functions

reading:

/// Read from file nodes available at launch. Ignored if None.
pub fn with_basic_nodes_from_file(
self,
optional_file: Option<impl AsRef<Path>>,
) -> Result<Self, io::Error> {
let Some(file_path) = optional_file else { return Ok(self) };
let reader = match std::fs::File::open(file_path.as_ref()) {
Ok(file) => io::BufReader::new(file),
Err(e) if e.kind() == ErrorKind::NotFound => return Ok(self),
Err(e) => Err(e)?,
};
info!(target: "net::peers", file = %file_path.as_ref().display(), "Loading saved peers");
let nodes: HashSet<NodeRecord> = serde_json::from_reader(reader)?;
Ok(self.with_basic_nodes(nodes))
}

writing

match network.write_peers_to_file(peers_file.as_path()) {

this change should be backwards compat so we should also try this format when reading:

let nodes: HashSet<NodeRecord> = serde_json::from_reader(reader)?;

Additional context

No response

Metadata

Metadata

Assignees

Labels

A-networkingRelated to networking in generalC-enhancementNew feature or requestD-good-first-issueNice and easy! A great choice to get started

Type

No type

Projects

Status

In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions