Skip to content

Commit

Permalink
nearcore: deprecate network configurations’s external_address field
Browse files Browse the repository at this point in the history
The field has never been used.  It’s only causes confusion as to its
purpose.  Deprecate it.

Issue: #7198
  • Loading branch information
mina86 committed Jul 30, 2022
1 parent b6f0c1f commit 9f388aa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

### Non-protocol Changes

* `network.external_address` field in `config.json` file is
deprecated. In fact it has never been used and only served to
confuse everyone.

## 1.28.0 [2022-07-27]

Expand Down
4 changes: 0 additions & 4 deletions chain/network-primitives/src/config_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ fn default_peer_stats_period() -> Duration {
pub struct Config {
/// Local address to listen for incoming connections.
pub addr: String,
/// Address to advertise to peers for them to connect.
/// If empty, will use the same port as the addr, and will introspect on the listener.
pub external_address: String,
/// Comma separated list of nodes to connect to.
/// Examples:
/// ed25519:86EtEy7epneKyrcJwSWP7zsisTkfDRH5CFVszt4qiQYw@31.192.22.209:24567
Expand Down Expand Up @@ -140,7 +137,6 @@ impl Default for Config {
fn default() -> Self {
Config {
addr: "0.0.0.0:24567".to_string(),
external_address: "".to_string(),
boot_nodes: "".to_string(),
whitelist_nodes: "".to_string(),
max_num_peers: default_max_num_peers(),
Expand Down
1 change: 0 additions & 1 deletion nearcore/res/example-config-gc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"network": {
"addr": "0.0.0.0:24567",
"external_address": "",
"boot_nodes": "ed25519:86EtEy7epneKyrcJwSWP7zsisTkfDRH5CFVszt4qiQYw@35.195.32.249:24567,ed25519:BFB78VTDBBfCY4jCP99zWxhXUcFAZqR22oSx2KEr8UM1@35.229.222.235:24567,ed25519:Cw1YyiX9cybvz3yZcbYdG7oDV6D7Eihdfc8eM1e1KKoh@35.195.27.104:24567,ed25519:33g3PZRdDvzdRpRpFRZLyscJdbMxUA3j3Rf2ktSYwwF8@34.94.132.112:24567,ed25519:CDQFcD9bHUWdc31rDfRi4ZrJczxg8derCzybcac142tK@35.196.209.192:24567",
"max_num_peers": 40,
"minimum_outbound_peers": 5,
Expand Down
1 change: 0 additions & 1 deletion nearcore/res/example-config-no-gc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
},
"network": {
"addr": "0.0.0.0:24567",
"external_address": "",
"boot_nodes": "ed25519:86EtEy7epneKyrcJwSWP7zsisTkfDRH5CFVszt4qiQYw@35.195.32.249:24567,ed25519:BFB78VTDBBfCY4jCP99zWxhXUcFAZqR22oSx2KEr8UM1@35.229.222.235:24567,ed25519:Cw1YyiX9cybvz3yZcbYdG7oDV6D7Eihdfc8eM1e1KKoh@35.195.27.104:24567,ed25519:33g3PZRdDvzdRpRpFRZLyscJdbMxUA3j3Rf2ktSYwwF8@34.94.132.112:24567,ed25519:CDQFcD9bHUWdc31rDfRi4ZrJczxg8derCzybcac142tK@35.196.209.192:24567",
"max_num_peers": 40,
"minimum_outbound_peers": 5,
Expand Down
37 changes: 27 additions & 10 deletions nearcore/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,36 @@ impl Default for Config {

impl Config {
pub fn from_file(path: &Path) -> anyhow::Result<Self> {
let mut unrecognised_fields = Vec::new();
let s = std::fs::read_to_string(path)
let contents = std::fs::read_to_string(path)
.with_context(|| format!("Failed to read config from {}", path.display()))?;
let config =
serde_ignored::deserialize(&mut serde_json::Deserializer::from_str(&s), |path| {
unrecognised_fields.push(path.to_string());
})
.with_context(|| format!("Failed to deserialize config from {}", path.display()))?;

let mut unrecognised_fields = Vec::new();
let config = serde_ignored::deserialize(
&mut serde_json::Deserializer::from_str(&contents),
|field| {
let field = field.to_string();
// TODO(mina86): Remove this deprecation notice some time by the
// end of 2022.
if field == "network.external_address" {
warn!(
target: "neard",
"{}: {field} is deprecated; please remove it from the config file",
path.display(),
);
} else {
unrecognised_fields.push(field);
}
},
)
.with_context(|| format!("Failed to deserialize config from {}", path.display()))?;
if !unrecognised_fields.is_empty() {
warn!("{}: encountered unrecognised fields: {:?}", path.display(), unrecognised_fields);
let s = if unrecognised_fields.len() > 1 { "s" } else { "" };
let fields = unrecognised_fields.join(", ");
warn!(
target: "neard",
"{}: encountered unrecognised field{s}: {fields}",
path.display(),
);
}

Ok(config)
}

Expand Down

0 comments on commit 9f388aa

Please sign in to comment.