node: Remove useless caching of node announcement
When initializing the `radicle-node` process, see `radicle-node/src/runtime.rs`, an attempt is made to read from a node announcement file. This file is never written, therefore all of these reads fail. Even though this caching mechanism might make sense or might have made sense at some point, it is dead code now, and therefore removed. Also, the fact that the file name was defined in the `radicle` crate is ugly.
This commit is contained in:
parent
efa7efacc4
commit
1cd3ad0784
|
|
@ -30,10 +30,9 @@ use radicle::{cob, git, storage, Storage};
|
||||||
|
|
||||||
use crate::control;
|
use crate::control;
|
||||||
use crate::node::{routing, NodeId};
|
use crate::node::{routing, NodeId};
|
||||||
use crate::service::message::NodeAnnouncement;
|
use crate::service::gossip;
|
||||||
use crate::service::{gossip, INITIAL_SUBSCRIBE_BACKLOG_DELTA};
|
|
||||||
use crate::wire;
|
use crate::wire;
|
||||||
use crate::wire::{Decode, Wire};
|
use crate::wire::Wire;
|
||||||
use crate::worker;
|
use crate::worker;
|
||||||
use crate::{service, LocalTime};
|
use crate::{service, LocalTime};
|
||||||
|
|
||||||
|
|
@ -135,7 +134,6 @@ impl Runtime {
|
||||||
{
|
{
|
||||||
let id = *signer.public_key();
|
let id = *signer.public_key();
|
||||||
let alias = config.alias.clone();
|
let alias = config.alias.clone();
|
||||||
let node_dir = home.node();
|
|
||||||
let network = config.network;
|
let network = config.network;
|
||||||
let rng = fastrand::Rng::new();
|
let rng = fastrand::Rng::new();
|
||||||
let clock = LocalTime::now();
|
let clock = LocalTime::now();
|
||||||
|
|
@ -166,41 +164,9 @@ impl Runtime {
|
||||||
log::info!(target: "node", "Default seeding policy set to '{}'", &policy);
|
log::info!(target: "node", "Default seeding policy set to '{}'", &policy);
|
||||||
log::info!(target: "node", "Initializing service ({network:?})..");
|
log::info!(target: "node", "Initializing service ({network:?})..");
|
||||||
|
|
||||||
let announcement = if let Some(ann) = fs::read(node_dir.join(node::NODE_ANNOUNCEMENT_FILE))
|
let announcement = service::gossip::node(&config, timestamp)
|
||||||
.ok()
|
.solve(Default::default())
|
||||||
.and_then(|ann| NodeAnnouncement::decode(&mut ann.as_slice()).ok())
|
.expect("Runtime::init: unable to solve proof-of-work puzzle");
|
||||||
.and_then(|ann| {
|
|
||||||
// If our announcement was made some time ago, the timestamp on it will be old,
|
|
||||||
// and it might not get gossiped to new nodes since it will be purged from caches.
|
|
||||||
// Therefore, we make sure it's never too old.
|
|
||||||
if clock - ann.timestamp.to_local_time() <= INITIAL_SUBSCRIBE_BACKLOG_DELTA {
|
|
||||||
Some(ann)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.and_then(|ann| {
|
|
||||||
if config.features() == ann.features
|
|
||||||
&& config.alias == ann.alias
|
|
||||||
&& config.external_addresses == ann.addresses.as_ref()
|
|
||||||
{
|
|
||||||
Some(ann)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
log::info!(
|
|
||||||
target: "node",
|
|
||||||
"Loaded existing node announcement from file (timestamp={}, work={})",
|
|
||||||
ann.timestamp,
|
|
||||||
ann.work(),
|
|
||||||
);
|
|
||||||
ann
|
|
||||||
} else {
|
|
||||||
service::gossip::node(&config, timestamp)
|
|
||||||
.solve(Default::default())
|
|
||||||
.expect("Runtime::init: unable to solve proof-of-work puzzle")
|
|
||||||
};
|
|
||||||
|
|
||||||
log::info!(target: "node", "Opening node database..");
|
log::info!(target: "node", "Opening node database..");
|
||||||
let db = home
|
let db = home
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,6 @@ pub const NODE_DB_FILE: &str = "node.db";
|
||||||
pub const POLICIES_DB_FILE: &str = "policies.db";
|
pub const POLICIES_DB_FILE: &str = "policies.db";
|
||||||
/// Filename of notifications database under the node directory.
|
/// Filename of notifications database under the node directory.
|
||||||
pub const NOTIFICATIONS_DB_FILE: &str = "notifications.db";
|
pub const NOTIFICATIONS_DB_FILE: &str = "notifications.db";
|
||||||
/// Filename of last node announcement, when running in debug mode.
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
pub const NODE_ANNOUNCEMENT_FILE: &str = "announcement.wire.debug";
|
|
||||||
/// Filename of last node announcement.
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
pub const NODE_ANNOUNCEMENT_FILE: &str = "announcement.wire";
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
||||||
pub enum PingState {
|
pub enum PingState {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue