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

Merged
merged 11 commits into from
Oct 21, 2024
Merged

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

  • TEST_DNS_NODE_ORIGIN is removed
  • iroh now defaults to using prod relays unless IROH_FORCE_STAGING_RELAYS is set to a non empty value

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: 148bac0

iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/pkarr.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Outdated Show resolved Hide resolved
iroh-net/src/endpoint.rs Show resolved Hide resolved
iroh/src/node/builder.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

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.

I don't think this is how it should be.

I agree with dig, we should drop the #[cfg(..)] completely, and solely rely on std::env::var(FORCE_STAGING_RELAYS).is_ok().

There's two permutations of this idea that I'm on the fence about:

  • we could require this env variable to be present at compile time, i.e. use std::env!("IROH_FORCE_STAGING_RELAYS"). This might be annoying if we try to test with, let's say, a pre-built iroh-doctor binary.
  • we could match on cfg!(test) || std::env::var(FORCE_STAGING_RELAYS).is_ok(). This way we make sure that any testing code always uses staging relays. This shouldn't be too bad. But also I still don't think this would be right to do. I want it to be possible to run the test env as similar to prod as possible, if I want to.

About insecure_skip_relay_cert_verify: This should just be gated on #[cfg(feature = "test-utils")] IMO.
But whether or not it's exposed is actually a concern outside of the scope of this PR, so this PR shouldn't change when this function actually is exposed.

Copy link
Contributor

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

You match on Ok(value) = std::env::var(...) if !value.is_empty(), but in the docs you write "if the ... env variable is set".

I think you should simply use std::env::var(ENV_FORCE_STAGING_RELAYS).is_ok().
If the env variable is not set, then std::env::var returns Err(NotPresent), so checking for is_ok() should be fine IMO.

With your current setup, this would not force staging relays:

$ IROH_FORCE_STAGING_RELAYS="" cargo run # ...

iroh-net/src/discovery/dns.rs Outdated Show resolved Hide resolved
iroh-net/src/discovery/pkarr.rs Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Oct 17, 2024

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2778/docs/iroh/

Last updated: 2024-10-21T10:59:45Z

@Arqu Arqu requested review from matheus23 and flub October 17, 2024 21:03
@Arqu Arqu force-pushed the arqu/fix_staging_relay_matrix branch from 556f174 to 3b9044e Compare October 18, 2024 07:15
Comment on lines 187 to 190
let pkarr_relay = match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) if !value.is_empty() => N0_DNS_PKARR_RELAY_STAGING,
_ => N0_DNS_PKARR_RELAY_PROD,
};
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 also do the cfg(test) dance as the other things, do, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@flub the N0_DNS_PKARR_RELAY_PROD values are distinct from the dns records ie. have /pkarr added. Do you want me to add a TEST_DNS_PKARR_RELAY similar to how it is on dns.rs right now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm no, I think TEST_DNS_NODE_ORIGIN is a special case: It uses the .test TLD which has special meaning in DNS resolvers!

We don't have any equivalent for any of the other infra identifiers.

Copy link
Contributor

Choose a reason for hiding this comment

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

So from my recollection TEST_DNS_NODE_ORIGIN was added so that it uses a special URL which will not be resolved by any normal resolvers and will only be resolved if you start a local resolver in the test using a helper function. This stops tests from hitting any external DNS server.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IIRC we basically didn't have any requests and this was more a precaution when we were dealing with the relays as well. (Though in spirit I do agree with it)

Comment on lines 326 to 329
#[cfg(not(test))]
let pkarr_relay = N0_DNS_PKARR_RELAY_PROD;
#[cfg(any(test, feature = "test-utils"))]
#[cfg(test)]
let pkarr_relay = N0_DNS_PKARR_RELAY_STAGING;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also match on the env var here, right?

Comment on lines 1247 to 1249
match std::env::var(ENV_FORCE_STAGING_RELAYS) {
Ok(value) if !value.is_empty() => RelayMode::Staging,
_ => RelayMode::Default,
Copy link
Contributor

Choose a reason for hiding this comment

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

Err. I'm a little confused.
Do we want to match on both env vars and cfg(test) now, or not?
Usage now seems somewhat inconsistent.

Perhaps we should just have a single fn use_staging_infra() -> bool somewhere instead of the ENV_FORCE_STAGING_RELAYS constant.
Then we can make sure our use is consistent.

Comment on lines 231 to 234
#[cfg(not(test))]
let relay_mode = RelayMode::Default;
#[cfg(any(test, feature = "test-utils"))]
#[cfg(test)]
let relay_mode = RelayMode::Staging;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO This should additionally test for the env variable here, too.

Comment on lines 267 to 270
#[cfg(not(test))]
let relay_mode = RelayMode::Default;
#[cfg(any(test, feature = "test-utils"))]
#[cfg(test)]
let relay_mode = RelayMode::Staging;
Copy link
Contributor

Choose a reason for hiding this comment

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

(same here)

iroh/src/node/builder.rs Outdated Show resolved Hide resolved

/// Returns `true` if the use of staging relays is forced.
pub fn force_staging_infra() -> bool {
matches!(std::env::var(ENV_FORCE_STAGING_RELAYS), Ok(value) if !value.is_empty())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can now handle the cfg(test) case here if we want to specifically. But as Frando mentioned, this only works in the tested crate.

@Arqu
Copy link
Collaborator Author

Arqu commented Oct 18, 2024

Revamped the thing again. This is the "slim" version.

  • No fluffy matching in each file, single generic function
  • No cfg(test) shenanigans
  • No TEST_urls
  • Works only by env var

@Arqu Arqu force-pushed the arqu/fix_staging_relay_matrix branch from 4ea7554 to 8d39c93 Compare October 19, 2024 11:06
@Arqu Arqu changed the title fix(cfg): make sure we use correct relays fix(cfg)!: make sure we use correct relays Oct 19, 2024
Comment on lines 61 to 63
match force_staging_infra() {
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
match force_staging_infra() {
true => Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string()),
false => Self::new(N0_DNS_NODE_ORIGIN_PROD.to_string()),
if force_staging_infra() {
Self::new(N0_DNS_NODE_ORIGIN_STAGING.to_string())
} else {
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.

I guess it'd be unusual to see a match on booleans. But honestly, it's shorter, and I'd almost say the match reads better in this case? I'm somewhat undecided :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I just followed like the others (where I let x = match ...) but technically here it is a simple if else. Updated to that 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

lol, I saw the other uses and was like "ah well, it's probably fine", but now we have it inconsistent 🙈
Anyhow, we can update another time.

Copy link
Contributor

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

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

I'm happy with this :)

(Btw: I didn't know we already set the IROH_FORCE_STAGING_RELAYS env var in testing CI! :D)

@Arqu Arqu enabled auto-merge October 21, 2024 10:57
@Arqu Arqu added this pull request to the merge queue Oct 21, 2024
Merged via the queue into main with commit 844b146 Oct 21, 2024
26 of 27 checks passed
@Arqu Arqu deleted the arqu/fix_staging_relay_matrix branch October 21, 2024 11:35
matheus23 pushed a commit that referenced this pull request Nov 14, 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

- `TEST_DNS_NODE_ORIGIN` is removed
- iroh now defaults to using prod relays unless
`IROH_FORCE_STAGING_RELAYS` is set to a non empty value

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants