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

init: abort if i2p/cjdns are chosen via -onlynet but are unreachable #25989

Merged
merged 2 commits into from
Sep 21, 2022

Conversation

mzumsande
Copy link
Contributor

If the networks i2p / cjdns are chosen via -onlynet but the user forgot to provide -i2psam / -cjdnsreachable, no outbound connections will be made - it would be nice to inform the user about that.
The solution proposed here mimics existing behavior for -onlynet=onion and non-specified -onion/-proxy where we already abort with an InitError - if reviewers would prefer to just print a warning, please say so.

The second commit adds CJDNS support to the debug-only addpeeraddress RPC allowing to add CJDNS addresses to addrman for testing and debug purposes. (if -cjdnsreachable=1)

This is the result of an IRC discussion with vasild.

@mzumsande mzumsande changed the title init: abort if i2p/cjdns are chosen via -onlynet but unreachable init: abort if i2p/cjdns are chosen via -onlynet but are unreachable Sep 2, 2022
@brunoerg
Copy link
Contributor

brunoerg commented Sep 2, 2022

Concept ACK

@ghost
Copy link

ghost commented Sep 3, 2022

If the networks i2p / cjdns are chosen via -onlynet but the user forgot to provide -i2psam / -cjdnsreachable, no outbound connections will be made - it would be nice to inform the user about that.

It's mentioned in the i2p doc that i2psam is required. Although I am not sure if everyone reads it.

The second commit adds CJDNS support to the debug-only addpeeraddress RPC allowing to add CJDNS addresses to addrman for testing and debug purposes. (if -cjdnsreachable=1)

Is this commit related to first change in any way?

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 3, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK b3576b7

@@ -332,6 +332,16 @@ def networks_dict(d):
msg = "Error: Invalid -i2psam address or hostname: 'def:xyz'"
self.nodes[1].assert_start_raises_init_error(expected_msg=msg)

self.log.info("Test passing invalid -onlynet=i2p without -i2psam raises expected init error")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "invalid" looks unnecessary here and below:

Suggested change
self.log.info("Test passing invalid -onlynet=i2p without -i2psam raises expected init error")
self.log.info("Test passing -onlynet=i2p without -i2psam raises expected init error")

@brunoerg
Copy link
Contributor

brunoerg commented Sep 5, 2022

The solution proposed here mimics existing behavior for -onlynet=onion and non-specified -onion/-proxy where we already abort with an InitError - if reviewers would prefer to just print a warning, please say so.

This approach is ok for me. But I slightly prefer a warning and it could set up -i2psam / -cjdnsreachable for me (like a "SoftSetBoolArg") if I chose one of them in -onlynet. Are there any malefits in doing so?

@mzumsande
Copy link
Contributor Author

mzumsande commented Sep 6, 2022

Is this commit related to first change in any way?

Not directly, it's a small and imo uncontroversial improvement to addpeeraddrress, which also deals with cjdns (and which might help to manually add cjdns peers to addrman if we can't find any, even if it's currently debug-only), so I thought might make sense to include here. If preferred, I could drop it.

This approach is ok for me. But I slightly prefer a warning

I chose an error because of the existing behavior with -onlynet=onion and missing -proxy, and I don't really see a reason why a different approach for different privacy networks would make sense. That being said, I'd be fine with a warning too, but in that case we probably should also just warn in the -onlynet=onion case.
I think it would be best to wait for the discussion in #24991 (which is more important than this PR and hopefully gets into 24.0, because it fixes a bug) and adapt this to PR to imitate whatever approach was chosen there.

(...) and it could set up -i2psam / -cjdnsreachable for me (like a "SoftSetBoolArg") if I chose one of them in -onlynet. Are there any malefits in doing so?

I think that soft-setting -i2psam would entail guessing the i2p proxy (default "127.0.0.1:7656" but configurable), which seems not ideal to me.

@brunoerg
Copy link
Contributor

brunoerg commented Sep 6, 2022

I think that soft-setting -i2psam would entail guessing the i2p proxy (default "127.0.0.1:7656" but configurable), which seems not ideal to me.

You're right. Thanks.

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

If you set -onlynet=cjdns -onlynet=ipv6, it shouldn't fail IMO. Maybe a warning.

@vasild
Copy link
Contributor

vasild commented Sep 12, 2022

@luke-jr,

Requesting -onlynet to an unreachable network is a sign the user does not know what they are doing / misconfigured bitcoind / the provided configuration will not have the expected effects. In such a case I think it is best to stop at startup.

In particular, that means:

  • for -onlynet=onion to work, a tor proxy must be provided either via -proxy, -onion or -torcontrol+-listenonion=1
  • for -onlynet=i2p to work, I2P proxy must be provided via -i2psam
  • for -onlynet=cjdns to work, the CJDNS network must be reachable in the environment where bitcoind is running and signaled to bitcoind by -cjdnsreachable

regardless of whether additional -onlynet options are used.

@fanquake
Copy link
Member

I think it would be best to wait for the discussion in #24991 (which is more important than this PR and hopefully gets into 24.0, because it fixes a bug) and adapt this to PR to imitate whatever approach was chosen there.

#24991 has now been merged, and will be part of 24.0.

...because -i2psam or -cjdnsreachable are not provided.
This mimics existing behavior for -onlynet=onion and non-specified proxy.
This allows us to add cjdns addresses to addrman for
testing and debug purposes (if -cjdnsreachable is true)
@mzumsande
Copy link
Contributor Author

b3576b7 to 68209a7: Rebased

I kept it at InitErrors, not warnings, see @vasild's rationale, plus I can't see a good reason why we should just have warnings for certain networks, but errors for others in a comparable situation.

@fanquake fanquake added P2P and removed Needs rebase labels Sep 19, 2022
@fanquake fanquake added this to the 24.0 milestone Sep 19, 2022
@mzumsande
Copy link
Contributor Author

@fanquake: I don't see a strong need to push this last-minute in 24.0, at least it shouldn't delay anything. In contrast to #24991 which fixed a bug (users with a reasonable configuration would get an InitError at startup) this is just a nice-to-have (users who don't read the docs and choose an unreasonable configuration will get an InitError now instead of getting no peers from that network).

@fanquake
Copy link
Member

I don't see a strong need to push this last-minute in 24.0, at least it shouldn't delay anything.

@mzumsande I've added the milestone as a nice-to-fix for 24.x, and this should be simple to backport. This wont be blocking branch-off.

@bitcoin bitcoin deleted a comment from DrahtBot Sep 19, 2022
Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK 68209a7

Copy link
Member

@dergoegge dergoegge left a comment

Choose a reason for hiding this comment

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

ACK 68209a7

fun fact: passing -onlynet=i2p takes a lot longer to error than passing -onlynet=cjdns because we load the chainstate (and other chain related data structures) before the i2p checks but after the cjdns checks. Not sure if that is worth a refactor (in a follow up) but in my opinion there is really no reason to have the chainstate loaded before doing all networking checks.

@fanquake fanquake merged commit 97f865b into bitcoin:master Sep 21, 2022
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Sep 21, 2022
...because -i2psam or -cjdnsreachable are not provided.
This mimics existing behavior for -onlynet=onion and non-specified proxy.

GitHub-Pull: bitcoin#25989
Rebased-From: a8a9ed6
fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Sep 21, 2022
This allows us to add cjdns addresses to addrman for
testing and debug purposes (if -cjdnsreachable is true)

GitHub-Pull: bitcoin#25989
Rebased-From: 68209a7
@fanquake
Copy link
Member

fanquake commented Sep 21, 2022

Added to #26133 for backporting to 24.x.

We'll do it in #26145.

fanquake added a commit that referenced this pull request Sep 21, 2022
… but are unreachable

68209a7 rpc: make addpeeraddress work with cjdns addresses (Martin Zumsande)
a8a9ed6 init: Abort if i2p/cjdns are chosen via -onlynet but unreachable (Martin Zumsande)

Pull request description:

  Identical commit from #25989

ACKs for top commit:
  fanquake:
    ACK 68209a7

Tree-SHA512: eec335df06b4c209cfe3473cb623828effd00c45a5dd605bb920edd265de1c789627482b005a51e89b8fc79cc4c5d26ff1fc306f2e4573897c5c7f083aa22861
@mzumsande mzumsande deleted the 202208_onlynet_init branch September 21, 2022 18:24
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 23, 2022
… but are unreachable

68209a7 rpc: make addpeeraddress work with cjdns addresses (Martin Zumsande)
a8a9ed6 init: Abort if i2p/cjdns are chosen via -onlynet but unreachable (Martin Zumsande)

Pull request description:

  If the networks i2p / cjdns are chosen via `-onlynet` but the user forgot to provide `-i2psam` / `-cjdnsreachable`, no outbound connections will be made - it would be nice to inform the user about that.
  The solution proposed here mimics existing behavior for `-onlynet=onion` and non-specified `-onion`/`-proxy` where we already abort with an InitError - if reviewers would prefer to just print a warning, please say so.

  The second commit adds CJDNS support to the debug-only `addpeeraddress` RPC allowing to add CJDNS addresses to addrman for testing and debug purposes. (if `-cjdnsreachable=1`)

  This is the result of an [IRC discussion](https://bitcoin-irc.chaincode.com/bitcoin-core-dev/2022-09-01#848066;) with vasild.

ACKs for top commit:
  vasild:
    ACK 68209a7
  dergoegge:
    ACK 68209a7

Tree-SHA512: 6db9787f01820190f14f90a0b39e4206603421eb7521f792879094d8bbf4d4d0bfd70665eadcc40994ac7941a15ab5a8d65c4779fba5634c0e6fa66eb0972b8d
@bitcoin bitcoin locked and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants