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

feat: override NetworkConfig from JSON config #8871

Merged
merged 3 commits into from
Apr 4, 2023

Conversation

VanBarbascu
Copy link
Contributor

Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.

@VanBarbascu VanBarbascu requested a review from a team as a code owner April 3, 2023 13:11
@VanBarbascu VanBarbascu requested a review from nikurt April 3, 2023 13:11
chain/network/src/config_json.rs Outdated Show resolved Hide resolved
pub network_config_overrides: NetworkConfigOverrides,
}

/// Override values from NetworkConfig.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please comment why specifically these values.

@@ -293,7 +355,7 @@ impl NetworkConfig {
},
event_sink: Sink::null(),
};
Ok(this)
Ok(Self::override_config(cfg.experimental.network_config_overrides, this))
Copy link
Contributor

Choose a reason for hiding this comment

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

Self::foo(this) is semantically equivalent to calling this.foo().

this.routing_table_update_rate_limit
},

node_addr: this.node_addr,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to avoid initialization of the fields as much as possible.

Would it be an Option (pun intended :) ) to change this function to accept a &mut Config and modify the fields that need to be overridden? That would let you not mention the fields that can already be set via a config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also considered it. It can be done by passing self and only overriding the appropriate values.
The reason that I went for this approach is, in case you add a new field to NetworkConfig, you will get an warning in this function and you will be able to decide if you want to expose it in the JSON config or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is a reasonable approach.
However, when someone adds a new field to NetworkConfig, why wouldn't they simply add a field here? How can they be made aware that each new field needs to be configurable, either directly, or via this emergency mechanism?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why wouldn't they simply add a field here
Authors can overlook this override function.
How can they be made aware that each new field needs to be configurable
They will be made aware by the rustc error saying that there is a missing field in this instantiation and they will read the comment. At this point they will decide if they want to keep the value or overriding it by going to NetworkConfigOverrides and adding the field there.

@@ -168,6 +168,68 @@ pub struct NetworkConfig {
}

impl NetworkConfig {
/// Here you can override the NewtworkConfig with values for the JSON config.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can

Technically, one does it by setting values in config.network.experimental.

Suggestion:

Overrides values of NetworkConfig that normally need not to be touched

chain/network/src/config.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@nikurt nikurt left a comment

Choose a reason for hiding this comment

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

Looks good but please add a unit test.

/// Overrides values of NetworkConfig with values for the JSON config.
/// We need all the values from NetworkConfig to be configurable.
/// We need this in case of emergency. It is faster to change the config than to recompile.
fn override_config(mut self, overrides: crate::config_json::NetworkConfigOverrides) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

[stylistic personal preference]
fn override(mut self) -> Self {} works, but I'd go for fn override(&mut self) {} to make the callsite less confusing.

x.override();
Ok(x)

seems clearer to me than

Ok(x.override())

Copy link
Contributor

@nikurt nikurt left a comment

Choose a reason for hiding this comment

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

Looks good but please add a unit test.

Added config.experimental.network_config_overrides field.
It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
@near-bulldozer near-bulldozer bot merged commit bf3c1ac into near:master Apr 4, 2023
@VanBarbascu VanBarbascu deleted the config_overrides branch April 4, 2023 18:53
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Apr 5, 2023
Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Apr 6, 2023
Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Apr 13, 2023
Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
nikurt pushed a commit that referenced this pull request Apr 14, 2023
Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
nikurt pushed a commit that referenced this pull request Apr 28, 2023
Added config.experimental.network_config_overrides field. It contains the overrides for the currently default values from NetworkConfig.

The JSON config override is done before the CLI overrides.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants