Skip to content
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

fix(cfg): make sure we use correct relays #2778

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Arqu
Copy link
Collaborator

@Arqu Arqu commented Oct 2, 2024

Description

This takes us back to only relying on the env var for forcing staging relays. However for tests it should still remain active with the test/feature combo by default.

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

@Arqu Arqu self-assigned this Oct 2, 2024
@Arqu Arqu requested a review from matheus23 October 2, 2024 20:30
Copy link

github-actions bot commented Oct 2, 2024

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: e0b63d5

@@ -14,10 +14,14 @@ pub const N0_DNS_NODE_ORIGIN_PROD: &str = "dns.iroh.link";
/// The n0 testing DNS node origin, for testing.
pub const N0_DNS_NODE_ORIGIN_STAGING: &str = "staging-dns.iroh.link";
/// Testing DNS node origin, must run server from [`crate::test_utils::DnsPkarrServer`].
#[cfg(any(test, feature = "test-utils"))]
#[cfg_attr(iroh_docsrs, doc(cfg(any(test, feature = "test-utils"))))]
#[cfg(test)]
Copy link
Contributor

@flub flub Oct 3, 2024

Choose a reason for hiding this comment

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

Please don't take away the cfg_attr on (public) items that have a cfg!

Suggested change
#[cfg(test)]
#[cfg(test)]
#[cfg_attr(iroh_docsrs, doc(cfg(test)))]

I know it's annoying you have to repeat the cfg inside the cfg_attr... Unfortunately that's the only way I could get this thing to work currently.

pub const TEST_DNS_NODE_ORIGIN: &str = "dns.iroh.test";

/// Environment variable to force the use of staging relays.
#[cfg(not(test))]
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))]
Copy link
Contributor

Choose a reason for hiding this comment

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

The cfg needs to be repeated inside the cfg_attr. The cfg is what the compiler sees. And because things are still sad, we need to repeat this inside the cfg_attr for the docs to work:

Suggested change
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))]
#[cfg_attr(iroh_docsrs, doc(cfg(not(test)))]

{
Self::new(TEST_DNS_NODE_ORIGIN.to_string())
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) => value == "1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Requiring a specific value here is a bit weird. UNIX has the custom of accepting any non-nil value for this kind of env var. Often people will use t, sometimes on.

Suggested change
Ok(value) => value == "1",
Ok(value) => !value.is_empty(),

Comment on lines +78 to +85
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) => value == "1",
Err(_) => false,
};
match force_staging_relays {
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()),
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) => value == "1",
Err(_) => false,
};
match force_staging_relays {
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()),
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()),
}
match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) if !value.is_empty() => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()),
_ => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()),
}

/// Environment variable to force the use of staging relays.
#[cfg(not(test))]
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))]
const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS";
Copy link
Contributor

Choose a reason for hiding this comment

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

You're adding this to more than one file. Let's add it to src/relays.rs and make it pub so we can document this as well.

@@ -321,9 +329,9 @@ impl PkarrResolver {
///
/// [number 0]: https://n0.computer
pub fn n0_dns() -> Self {
#[cfg(not(any(test, feature = "test-utils")))]
#[cfg(not(all(test, feature = "test-utils")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

didn't @matheus23 say this doesn't work for something?

@@ -58,8 +58,6 @@ pub use iroh_base::node_addr::{AddrInfo, NodeAddr};
const DISCOVERY_WAIT_PERIOD: Duration = Duration::from_millis(500);

/// Environment variable to force the use of staging relays.
#[cfg(not(any(test, feature = "test-utils")))]
#[cfg_attr(iroh_docsrs, doc(cfg(not(any(test, feature = "test-utils")))))]
const ENV_FORCE_STAGING_RELAYS: &str = "IROH_FORCE_STAGING_RELAYS";
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to one place as discussed.

@@ -1247,14 +1245,10 @@ fn proxy_url_from_env() -> Option<Url> {
/// Otherwise, it will return `RelayMode::Default`.
pub fn default_relay_mode() -> RelayMode {
// Use staging in testing
#[cfg(not(any(test, feature = "test-utils")))]
let force_staging_relays = match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) => value == "1",
Copy link
Contributor

Choose a reason for hiding this comment

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

should be any non-nil value. Maybe we can add a pub(crate) function to read this variable and also put it in src/relay.rs. Otherwise this behaviour gets to easily different between different call sites.

@@ -1247,14 +1245,10 @@ fn proxy_url_from_env() -> Option<Url> {
/// Otherwise, it will return `RelayMode::Default`.
pub fn default_relay_mode() -> RelayMode {
// Use staging in testing
#[cfg(not(any(test, feature = "test-utils")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

this one does not have to stay at cfg(not(test))?

@@ -231,9 +231,9 @@ fn mk_external_rpc() -> IrohServerEndpoint {
impl Default for Builder<iroh_blobs::store::mem::Store> {
fn default() -> Self {
// Use staging in testing
#[cfg(not(any(test, feature = "test-utils")))]
#[cfg(not(all(test, feature = "test-utils")))]
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be just cfg(not(test))? If someone is requesting test-utils they can still enable test themselves. Unless this breaks one of the benchmarks again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

2 participants