This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Combine default values used at initialization in a trait #6857
Merged
+94
−39
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -41,8 +41,44 @@ pub(crate) const NODE_NAME_MAX_LENGTH: usize = 64; | |||||
| /// default sub directory to store network config | ||||||
| pub(crate) const DEFAULT_NETWORK_CONFIG_PATH: &'static str = "network"; | ||||||
|
|
||||||
| /// Default configuration values used by Substrate | ||||||
| /// | ||||||
| /// These values will be used by [`CliConfiguritation`] to set | ||||||
| /// default values for e.g. the listen port or the RPC port. | ||||||
| pub trait DefaultConfigurationValues { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danforbes any ideas of what we could call this instead? 😅
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How's about
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's actually better 👍 |
||||||
| /// The port Substrate should listen on for p2p connections. | ||||||
| /// | ||||||
| /// By default this is `30333`. | ||||||
| fn p2p_listen_port() -> u16 { | ||||||
| 30333 | ||||||
| } | ||||||
|
|
||||||
| /// The port Substrate should listen on for websocket connections. | ||||||
| /// | ||||||
| /// By default this is `9944`. | ||||||
| fn rpc_ws_listen_port() -> u16 { | ||||||
| 9944 | ||||||
| } | ||||||
|
|
||||||
| /// The port Substrate should listen on for http connections. | ||||||
| /// | ||||||
| /// By default this is `9933`. | ||||||
| fn rpc_http_listen_port() -> u16 { | ||||||
| 9933 | ||||||
| } | ||||||
|
|
||||||
| /// The port Substrate should listen on for prometheus connections. | ||||||
| /// | ||||||
| /// By default this is `9615`. | ||||||
| fn prometheus_listen_port() -> u16 { | ||||||
| 9615 | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl DefaultConfigurationValues for () {} | ||||||
|
|
||||||
| /// A trait that allows converting an object to a Configuration | ||||||
| pub trait CliConfiguration: Sized { | ||||||
| pub trait CliConfiguration<DCV: DefaultConfigurationValues = ()>: Sized { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// Get the SharedParams for this object | ||||||
| fn shared_params(&self) -> &SharedParams; | ||||||
|
|
||||||
|
|
@@ -122,6 +158,7 @@ pub trait CliConfiguration: Sized { | |||||
| client_id: &str, | ||||||
| node_name: &str, | ||||||
| node_key: NodeKeyConfig, | ||||||
| default_listen_port: u16, | ||||||
| ) -> Result<NetworkConfiguration> { | ||||||
| Ok(if let Some(network_params) = self.network_params() { | ||||||
| network_params.network_config( | ||||||
|
|
@@ -131,6 +168,7 @@ pub trait CliConfiguration: Sized { | |||||
| client_id, | ||||||
| node_name, | ||||||
| node_key, | ||||||
| default_listen_port, | ||||||
| ) | ||||||
| } else { | ||||||
| NetworkConfiguration::new( | ||||||
|
|
@@ -257,22 +295,22 @@ pub trait CliConfiguration: Sized { | |||||
| /// Get the RPC HTTP address (`None` if disabled). | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn rpc_http(&self) -> Result<Option<SocketAddr>> { | ||||||
| Ok(Default::default()) | ||||||
| fn rpc_http(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> { | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Get the RPC IPC path (`None` if disabled). | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn rpc_ipc(&self) -> Result<Option<String>> { | ||||||
| Ok(Default::default()) | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Get the RPC websocket address (`None` if disabled). | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn rpc_ws(&self) -> Result<Option<SocketAddr>> { | ||||||
| Ok(Default::default()) | ||||||
| fn rpc_ws(&self, _default_listen_port: u16) -> Result<Option<SocketAddr>> { | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Returns the RPC method set to expose. | ||||||
|
|
@@ -287,21 +325,21 @@ pub trait CliConfiguration: Sized { | |||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn rpc_ws_max_connections(&self) -> Result<Option<usize>> { | ||||||
| Ok(Default::default()) | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Get the RPC cors (`None` if disabled) | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| /// By default this is `Some(Vec::new())`. | ||||||
| fn rpc_cors(&self, _is_dev: bool) -> Result<Option<Vec<String>>> { | ||||||
| Ok(Some(Vec::new())) | ||||||
| } | ||||||
|
|
||||||
| /// Get the prometheus configuration (`None` if disabled) | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn prometheus_config(&self) -> Result<Option<PrometheusConfig>> { | ||||||
| Ok(Default::default()) | ||||||
| fn prometheus_config(&self, _default_listen_port: u16) -> Result<Option<PrometheusConfig>> { | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Get the telemetry endpoints (if any) | ||||||
|
|
@@ -318,14 +356,14 @@ pub trait CliConfiguration: Sized { | |||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn telemetry_external_transport(&self) -> Result<Option<ExtTransport>> { | ||||||
| Ok(Default::default()) | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Get the default value for heap pages | ||||||
| /// | ||||||
| /// By default this is `None`. | ||||||
| fn default_heap_pages(&self) -> Result<Option<u64>> { | ||||||
| Ok(Default::default()) | ||||||
| Ok(None) | ||||||
| } | ||||||
|
|
||||||
| /// Returns an offchain worker config wrapped in `Ok(_)` | ||||||
|
|
@@ -445,6 +483,7 @@ pub trait CliConfiguration: Sized { | |||||
| client_id.as_str(), | ||||||
| self.node_name()?.as_str(), | ||||||
| node_key, | ||||||
| DCV::p2p_listen_port(), | ||||||
| )?, | ||||||
| keystore: self.keystore_config(&config_dir)?, | ||||||
| database: self.database_config(&config_dir, database_cache_size, database)?, | ||||||
|
|
@@ -453,13 +492,13 @@ pub trait CliConfiguration: Sized { | |||||
| pruning: self.pruning(unsafe_pruning, &role)?, | ||||||
| wasm_method: self.wasm_method()?, | ||||||
| execution_strategies: self.execution_strategies(is_dev, is_validator)?, | ||||||
| rpc_http: self.rpc_http()?, | ||||||
| rpc_ws: self.rpc_ws()?, | ||||||
| rpc_http: self.rpc_http(DCV::rpc_http_listen_port())?, | ||||||
| rpc_ws: self.rpc_ws(DCV::rpc_ws_listen_port())?, | ||||||
| rpc_ipc: self.rpc_ipc()?, | ||||||
| rpc_methods: self.rpc_methods()?, | ||||||
| rpc_ws_max_connections: self.rpc_ws_max_connections()?, | ||||||
| rpc_cors: self.rpc_cors(is_dev)?, | ||||||
| prometheus_config: self.prometheus_config()?, | ||||||
| prometheus_config: self.prometheus_config(DCV::prometheus_listen_port())?, | ||||||
| telemetry_endpoints: self.telemetry_endpoints(&chain_spec)?, | ||||||
| telemetry_external_transport: self.telemetry_external_transport()?, | ||||||
| default_heap_pages: self.default_heap_pages()?, | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this parameter actually a default value or is this something that is being configured by the user somehow and then actually used to construct an instance of some type?
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.
The default ports are hardcoded in sc-cli but during runtime the user can override them. Cumulus has a third way to this approach: it overrides the default ports so the user can still override at runtime but the default value would be different.
This is because cumulus has 2 nodes running.