Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,969 changes: 1,058 additions & 911 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ axum = { version = "0.8", default-features = false }
anyhow = { version = "1", default-features = false }
arc-swap = { version = "1", default-features = false }
arrayvec = { version = "0.7", default-features = false }
arti-client = { version = "0.33", default-features = false }
arti-client = { version = "0.43", default-features = false }
async-trait = { version = "0.1", default-features = false }
bitflags = { version = "2", default-features = false }
blake3 = { version = "1", default-features = false }
Expand Down Expand Up @@ -192,7 +192,7 @@ randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev
rand = { version = "0.8", default-features = false }
rand_distr = { version = "0.4", default-features = false }
rayon = { version = "1", default-features = false }
safelog = { version = "0.4", default-features = false }
safelog = { version = "0.8", default-features = false }
serde_bytes = { version = "0.11", default-features = false }
serde_json = { version = "1", default-features = false }
serde = { version = "1", default-features = false }
Expand All @@ -209,12 +209,12 @@ tower = { version = "0.5", default-features = false }
tower-http = { version = "0.6", default-features = false }
toml = { version = "0.9", default-features = false }
toml_edit = { version = "0.23", default-features = false }
tor-cell = { version = "0.33", default-features = false }
tor-config-path = { version = "0.33", default-features = false }
tor-hsservice = { version = "0.33", default-features = false }
tor-persist = { version = "0.33", default-features = false }
tor-proto = { version = "0.33", default-features = false }
tor-rtcompat = { version = "0.33", default-features = false }
tor-cell = { version = "0.43", default-features = false }
tor-config-path = { version = "0.43", default-features = false }
tor-hsservice = { version = "0.43", default-features = false }
tor-persist = { version = "0.43", default-features = false }
tor-proto = { version = "0.43", default-features = false }
tor-rtcompat = { version = "0.43", default-features = false }
tracing-appender = { version = "0.2", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
tracing = { version = "0.1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion binaries/cuprated/src/config/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ pub fn tor_net_seed_nodes(network: Network) -> Vec<OnionAddr> {
let seeds = match network {
Network::Mainnet => [
"zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
"qz43zul2x56jexzoqgkx2trzwcfnr6l3hbtfcfx54g4r3eahy3bssjyd.onion:18083",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

seed node was updated upstream

"lykcas4tus7mkm4bhsgqe4drtd4awi7gja24goscc47xfgzj54yofyqd.onion:18083",
"plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
"plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
"plowsofe6cleftfmk2raiw5h2x66atrik3nja4bfd3zrfa2hdlgworad.onion:18083",
Expand Down
10 changes: 6 additions & 4 deletions binaries/cuprated/src/tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct TorContext {
// -------- Only in Arti mode
/// Arti bootstrapped [`TorClient`].
#[cfg(feature = "arti")]
pub bootstrapped_client: Option<TorClient<PreferredRuntime>>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is no longer clone, so its now Arced

pub bootstrapped_client: Option<Arc<TorClient<PreferredRuntime>>>,
/// Arti bootstrapped client config
#[cfg(feature = "arti")]
pub arti_client_config: Option<TorClientConfig>,
Expand Down Expand Up @@ -123,7 +123,9 @@ pub async fn initialize_tor_if_enabled(launch_ctx: &LaunchContext) -> TorContext

/// Initialize Arti Tor client.
#[cfg(feature = "arti")]
async fn initialize_arti_client(config: &Config) -> (TorClient<PreferredRuntime>, TorClientConfig) {
async fn initialize_arti_client(
config: &Config,
) -> (Arc<TorClient<PreferredRuntime>>, TorClientConfig) {
// Configuration
let mut tor_config = TorClientConfig::builder();

Expand All @@ -149,7 +151,7 @@ async fn initialize_arti_client(config: &Config) -> (TorClient<PreferredRuntime>
if config.tor.arti.isolated_circuit {
let mut stream_prefs = StreamPrefs::new();
stream_prefs.isolate_every_stream();
tor_client.set_stream_prefs(stream_prefs);
tor_client = tor_client.with_prefs(stream_prefs);
}

(tor_client, tor_config)
Expand Down Expand Up @@ -207,7 +209,7 @@ pub fn transport_clearnet_arti_config(ctx: &TorContext) -> TransportConfig<Clear

TransportConfig::<ClearNet, Arti> {
client_config: ArtiClientConfig {
client: bootstrapped_client.clone(),
client: Arc::clone(bootstrapped_client),
},
server_config: None,
}
Expand Down
2 changes: 0 additions & 2 deletions consensus/src/tests/context/rx_vms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ fn rx_heights_consistent() {
}

#[tokio::test]
#[expect(unused_qualifications, reason = "false positive in tokio macro")]
async fn rx_vm_created_on_hf_12() {
let db = DummyDatabaseBuilder::default().finish(Some(10));

Expand All @@ -53,7 +52,6 @@ async fn rx_vm_created_on_hf_12() {
}

#[tokio::test]
#[expect(unused_qualifications, reason = "false positive in tokio macro")]
async fn rx_vm_pop_blocks() {
let db = DummyDatabaseBuilder::default().finish(Some(2_000_000));

Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ ignore = [
# [possible values: any SPDX 3.11 short identifier (+ optional exception)].
allow = [
# Nothing required - free to use without permission.
"0BSD", # https://spdx.org/licenses/0BSD.html
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
"Unlicense",

Expand Down
10 changes: 8 additions & 2 deletions net/wire/src/network_address/epee_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ impl EpeeObjectBuilder<NetworkAddress> for TaggedNetworkAddress {
}

fn finish(self) -> cuprate_epee_encoding::Result<NetworkAddress> {
self.try_into()
.map_err(|_| cuprate_epee_encoding::Error::Value("Invalid network address".to_string()))
let ty = self.ty;
let host = self.addr.as_ref().and_then(|a| a.host.clone());

self.try_into().map_err(|_| {
cuprate_epee_encoding::Error::Value(format!(
"Invalid network address (type: {ty:?}, host: {host:?})"
))
})
}
}

Expand Down
12 changes: 8 additions & 4 deletions net/wire/src/network_address/onion_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@ impl OnionAddr {
return Err(OnionAddrParsingError::InvalidTld(String::from(tld)));
}

// The domain part must only contain base32 characters.
// The domain part must only contain base32 characters. monerod also
// accepts uppercase characters.
if !domain
.as_bytes()
.iter()
.copied()
.all(|c| c.is_ascii_lowercase() || (b'2'..=b'7').contains(&c))
.all(|c| c.is_ascii_alphabetic() || (b'2'..=b'7').contains(&c))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was the thing causing issues with Tor, it prevents you from connecting to nodes that send upper case addresses.

{
return Err(OnionAddrParsingError::NonBase32Char);
}

Ok(addr.as_bytes()[..56]
let mut domain: [u8; 56] = addr.as_bytes()[..56]
.try_into()
.unwrap_or_else(|e| panic!("We just validated address: {addr} : {e}")))
.unwrap_or_else(|e| panic!("We just validated address: {addr} : {e}"));
domain.make_ascii_lowercase();

Ok(domain)
}

/// Generate an onion address string.
Expand Down
21 changes: 12 additions & 9 deletions p2p/p2p-transport/src/arti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tokio_util::codec::{FramedRead, FramedWrite};
use tor_cell::relaycell::msg::Connected;
use tor_config_path::CfgPathResolver;
use tor_hsservice::{handle_rend_requests, OnionService, RunningOnionService};
use tor_proto::stream::IncomingStreamRequest;
use tor_proto::client::stream::IncomingStreamRequest;
use tor_rtcompat::PreferredRuntime;

use cuprate_p2p_core::{ClearNet, NetworkZone, Tor, Transport};
Expand All @@ -32,7 +32,7 @@ use crate::DisabledListener;
#[derive(Clone)]
pub struct ArtiClientConfig {
/// Arti bootstrapped client
pub client: TorClient<PreferredRuntime>,
pub client: Arc<TorClient<PreferredRuntime>>,
}

pub struct ArtiServerConfig {
Expand All @@ -42,23 +42,23 @@ pub struct ArtiServerConfig {
pub port: u16,

// Mandatory resources for launching the onion service
client: TorClient<PreferredRuntime>,
client: Arc<TorClient<PreferredRuntime>>,
path_resolver: Arc<CfgPathResolver>,
}

impl ArtiServerConfig {
pub fn new(
onion_svc: OnionService,
port: u16,
client: &TorClient<PreferredRuntime>,
client: &Arc<TorClient<PreferredRuntime>>,
config: &TorClientConfig,
) -> Self {
let path_resolver: &CfgPathResolver = config.as_ref();

Self {
onion_svc,
port,
client: client.clone(),
client: Arc::clone(client),
path_resolver: Arc::new(path_resolver.clone()),
}
}
Expand Down Expand Up @@ -135,17 +135,20 @@ impl Transport<Tor> for Arti {
async fn incoming_connection_listener(
config: Self::ServerConfig,
) -> Result<Self::Listener, io::Error> {
let not_running =
|e: arti_client::Error| io::Error::new(ErrorKind::NotConnected, e.to_string());

// Launch onion service
#[expect(clippy::clone_on_ref_ptr)]
let (svc, rdv_stream) = config
.onion_svc
.launch(
config.client.runtime().clone(),
config.client.dirmgr().clone(),
config.client.hs_circ_pool().clone(),
config.client.dirmgr().map_err(not_running)?,
config.client.hs_circ_pool().map_err(not_running)?,
config.path_resolver,
)
.unwrap();
.unwrap()
.expect("the onion service is never disabled in its config");

// Accept all rendez-vous and await correct stream request
#[expect(clippy::wildcard_enum_match_arm)]
Expand Down
26 changes: 19 additions & 7 deletions p2p/p2p/src/connection_maintainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ where

/// Connects to random seeds to get peers and immediately disconnects
#[instrument(level = "info", skip(self))]
#[expect(clippy::significant_drop_tightening)]
async fn connect_to_random_seeds(&mut self) -> Result<(), OutboundConnectorError> {
let seeds = self
.config
Expand All @@ -118,23 +117,36 @@ where
for seed in seeds {
tracing::info!("Getting peers from seed node: {}", seed);

let addr = *seed;
let fut = timeout(
HANDSHAKE_TIMEOUT,
self.connector_svc
.ready()
.await
.expect("Connector had an error in `poll_ready`")
.call(ConnectRequest {
addr: *seed,
permit: None,
}),
.call(ConnectRequest { addr, permit: None }),
);
// Spawn the handshake on a separate task with a timeout, so we don't get stuck connecting to a peer.
handshake_futs.spawn(fut);
handshake_futs.spawn(
async move {
match fut.await {
Err(_) => {
tracing::warn!("Timed out connecting to seed node: {addr}");
false
}
Ok(Err(e)) => {
tracing::warn!("Failed to connect to seed node {addr}: {e}");
false
}
Ok(Ok(_)) => true,
}
}
.instrument(Span::current()),
);
}

while let Some(res) = handshake_futs.join_next().await {
if matches!(res, Err(_) | Ok(Err(_) | Ok(Err(_)))) {
if !res.unwrap_or(false) {
allowed_errors -= 1;
}
}
Expand Down
Loading