-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for lists of peers in the config #16376
Add support for lists of peers in the config #16376
Conversation
This looks like a good idea, and low risk. Thanks, Felix, and good luck with this PR. |
I'd love to see this. I run several nodes which I want to keep in a fully connected mesh with each other. Currently, I achieve this with the peer whitelist and a cronjob that connects a node manually to the desired peers via the CLI. Being able to get rid of that cronjob and directly have this in the config would be great. Second use-case: since another of Felix' recent PRs was merged, I run my farmer processes connected to two full nodes, for redundancy. Have to manually connect to the second full node, though. And if the farmer loses connection to the secondary node, it does not automatically re-connect (which it does for the primary full node peer from the config) -- so, same cronjob to stay connected to the secondary. |
13b2b73
to
75fe673
Compare
75fe673
to
713dfb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this feature addition makes sense and is valuable. Thanks Felix for both suggesting it and providing the implementation! Bonus, while reviewing this I found we needed to fix some mutable default parameter values. #16472
When a singular peer info is present in the config it is used as is, same as before, it just gets wrapped into a list with it being the only member. In this case the peer list should it be present as well gets ignored. When no singular peer info is present, the peer list is retrieved with a default of an empty list.
Is there a particular reason for this behavior? The first thing that popped into my head was to have the singular peer entry just treated as if it were another entry in the plural peers list. I was thinking that leaving the singular peer entry at all is mostly a backwards compatibility feature (which is good, thanks).
For the tests, maybe look at uses o @datacases
, a small @pytest.mark.parametrize
wrapper we use some, to provide a single parametrized test with the many cases.
No, it would probably make sense to merge them in this case yes 👍 |
This is only for the tests i wrote, right? Together with the change to assert a set of unresolved peer infos this will work nicely Do you have suggestions regarding testing the async_main()s? |
Yes, that comment is just about the pattern for coding the tests.
If you really want to go for this, you could setup a temporary root (we have a fixture), edit the config (we have helper functions and patterns) then setup the services you want it to connect (we have fixtures), call the |
Yeah, testing the i'll omit tests for those for now 👍 |
Yep, plenty of corners and we might need to adjust some params etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to have this new configuration in the initial-config.yaml
file. I think we can remove the existing singular case and add the peer listed there as the only entry in the new plural list.
Once we have this ready, I'll create an ephemeral testnet to make sure everything still launches ok. This will be a partial stop gap for the lack of top level integration test coverage.
Seems like some tests are failing, because the configure command assumes the key is present What should be its behaviour when only a list is present? |
It reads to me like that code should be updated to set the plural list value for the |
which entry in the list would you update, the first?
Sadly im not following here, why would we remove anything? |
At a glance, this is what I was thinking. diff --git a/chia/simulator/setup_services.py b/chia/simulator/setup_services.py
index 799134941..6582b7ee4 100644
--- a/chia/simulator/setup_services.py
+++ b/chia/simulator/setup_services.py
@@ -309,11 +309,15 @@ async def setup_wallet_node(
service_config["introducer_peer"] = None
if full_node_port is not None:
- service_config["full_node_peer"] = {}
- service_config["full_node_peer"]["host"] = self_hostname
- service_config["full_node_peer"]["port"] = full_node_port
+ service_config["full_node_peers"] = [
+ {
+ "host": self_hostname,
+ "port": full_node_port,
+ },
+ ]
else:
- del service_config["full_node_peer"]
+ service_config.pop("full_node_peer", None)
+ service_config.pop("full_node_peers", None)
service = create_wallet_service(
local_bt.root_path,
@@ -413,11 +417,16 @@ async def setup_farmer(
service_config["rpc_port"] = uint16(0)
config_pool["xch_target_address"] = encode_puzzle_hash(b_tools.pool_ph, "xch")
- if full_node_port:
- service_config["full_node_peer"]["host"] = self_hostname
- service_config["full_node_peer"]["port"] = full_node_port
+ if full_node_port is not None:
+ service_config["full_node_peers"] = [
+ {
+ "host": self_hostname,
+ "port": full_node_port,
+ },
+ ]
else:
- del service_config["full_node_peer"]
+ service_config.pop("full_node_peer", None)
+ service_config.pop("full_node_peers", None)
service = create_farmer_service(
root_path, |
Oh you are talking about the simulator, yeah, that looks good i was talking about the configure cmd used on the cli, which currently will break as well im unsure how this command should work with a list, as we probably cant uniquely identify the "self" peer |
I'm going to chat around about this. Maybe ping me tomorrow if I haven't gotten an answer to you here. |
I think this might make some sense for I believe you are referring to It's seems mostly a testing option, and I don't know how much it's really used. |
Chris pointed out |
That is already done yeah 👍
Yeah, setting the first entries port was my first thought as well, as that is very likely the self peer in most cases
I'd probably handle it the same here, for the full node it just gets updated same as before as that did not change, and for the harvester its the first entry as well |
65a3646
to
b38a3a3
Compare
Rebased to current main to hopefully get rid of test flakes |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
…onfig # Conflicts: # chia/cmds/configure.py # chia/cmds/sim_funcs.py # chia/util/config.py # chia/util/initial-config.yaml
Conflicts have been resolved. A maintainer will review the pull request shortly. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
…onfig # Conflicts: # chia/server/start_farmer.py
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Coverage diff exemption Much thanks for the PR |
Purpose:
Currently it is possible to connect to a single peer via the peer info in the
config.yaml
, for example:It is currently not possible to connect to multiple predefined peers, one has to use the cli/rpc to connect to additional peers after startup.
This PR adds support for a list of peers in the
config.yaml
, the key name just gets as
added, for example:Note: This is currently only supported for farmer and full node peers, as imho those are the only ones where multiple peers make sense at the moment.
Current Behavior:
Connecting to multiple predefined peers is not possible.
New Behavior:
When a singular peer info is present in the config it is used as is, same as before, it just gets wrapped into a set with it being the only member. In case the peer list should be present as well both get merged together.
When no singular peer info is present, the peer list is retrieved with a default of an empty set.
Testing Notes:
I added tests for the new
get_unresolved_peer_infos()
function. Its usages in thestart_<service>.py
files are not currently tested as im unsure on how to best test those as they use globals and are generally hard to work with (async_main()
that is). If there is a recommended way to test those please let me know and i'll happily add tests for those as well.It's also important to note that i did not change the
configure
cli, it will continue to write to the singular entry in the config. I added support for farmer and full node node types. In the config there are some more peer infos (harvester, wallet, timelord, introducer) which currently are either unused or rely on being a singular value to set service wide values (enable_private_networks).