Skip to content

Commit 7c04a10

Browse files
authored
Added option to set incentives address during mix and gateway init (#419)
1 parent 7eaef53 commit 7c04a10

File tree

15 files changed

+97
-2
lines changed

15 files changed

+97
-2
lines changed

common/client-libs/validator-client/src/models/gateway.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl GatewayRegistrationInfo {
5555
sphinx_key: String,
5656
version: String,
5757
location: String,
58+
incentives_address: Option<String>,
5859
) -> Self {
5960
GatewayRegistrationInfo {
6061
node_info: NodeInfo {
@@ -63,6 +64,7 @@ impl GatewayRegistrationInfo {
6364
sphinx_key,
6465
version,
6566
location,
67+
incentives_address: incentives_address.unwrap_or_else(|| "".to_string()),
6668
},
6769
clients_host,
6870
}

common/client-libs/validator-client/src/models/mixnode.rs

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl MixRegistrationInfo {
5555
version: String,
5656
location: String,
5757
layer: u64,
58+
incentives_address: Option<String>,
5859
) -> Self {
5960
MixRegistrationInfo {
6061
node_info: NodeInfo {
@@ -63,6 +64,7 @@ impl MixRegistrationInfo {
6364
sphinx_key,
6465
version,
6566
location,
67+
incentives_address: incentives_address.unwrap_or_else(|| "".to_string()),
6668
},
6769
layer,
6870
}

common/client-libs/validator-client/src/models/node.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ pub(crate) struct NodeInfo {
2222
pub(crate) sphinx_key: String,
2323
pub(crate) version: String,
2424
pub(crate) location: String,
25+
pub(crate) incentives_address: String,
2526
}

gateway/src/commands/init.rs

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
103103
.help("REST endpoint of the validator the node is registering presence with")
104104
.takes_value(true),
105105
)
106+
.arg(
107+
Arg::with_name("incentives-address")
108+
.long("incentives-address")
109+
.help("Optional, if participating in the incentives program, payment address")
110+
.takes_value(true),
111+
)
106112
}
107113

108114
fn show_incentives_url() {

gateway/src/commands/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,9 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi
102102
config = config.with_location(location);
103103
}
104104

105+
if let Some(incentives_address) = matches.value_of("incentives-address") {
106+
config = config.with_incentives_address(incentives_address);
107+
}
108+
105109
config
106110
}

gateway/src/config/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ where
139139
deserializer.deserialize_any(DurationVisitor)
140140
}
141141

142+
fn deserialize_option_string<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
143+
where
144+
D: Deserializer<'de>,
145+
{
146+
let s = String::deserialize(deserializer)?;
147+
if s.is_empty() {
148+
Ok(None)
149+
} else {
150+
Ok(Some(s))
151+
}
152+
}
153+
142154
pub fn missing_string_value() -> String {
143155
MISSING_VALUE.to_string()
144156
}
@@ -380,6 +392,11 @@ impl Config {
380392
self
381393
}
382394

395+
pub fn with_incentives_address<S: Into<String>>(mut self, incentives_address: S) -> Self {
396+
self.gateway.incentives_address = Some(incentives_address.into());
397+
self
398+
}
399+
383400
// getters
384401
pub fn get_config_file_save_location(&self) -> PathBuf {
385402
self.config_directory().join(Self::config_file_name())
@@ -464,6 +481,10 @@ impl Config {
464481
pub fn get_version(&self) -> &str {
465482
&self.gateway.version
466483
}
484+
485+
pub fn get_incentives_address(&self) -> Option<String> {
486+
self.gateway.incentives_address.clone()
487+
}
467488
}
468489

469490
#[derive(Debug, Deserialize, PartialEq, Serialize)]
@@ -500,6 +521,10 @@ pub struct Gateway {
500521
/// nym_home_directory specifies absolute path to the home nym gateways directory.
501522
/// It is expected to use default value and hence .toml file should not redefine this field.
502523
nym_root_directory: PathBuf,
524+
525+
/// Optional, if participating in the incentives program, payment address.
526+
#[serde(deserialize_with = "deserialize_option_string")]
527+
incentives_address: Option<String>,
503528
}
504529

505530
impl Gateway {
@@ -536,6 +561,7 @@ impl Default for Gateway {
536561
public_sphinx_key_file: Default::default(),
537562
validator_rest_url: DEFAULT_VALIDATOR_REST_ENDPOINT.to_string(),
538563
nym_root_directory: Config::default_root_directory(),
564+
incentives_address: None,
539565
}
540566
}
541567
}

gateway/src/config/template.rs

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ private_sphinx_key_file = '{{ gateway.private_sphinx_key_file }}'
4848
# Path to file containing public sphinx key.
4949
public_sphinx_key_file = '{{ gateway.public_sphinx_key_file }}'
5050
51+
# Optional, if participating in the incentives program, payment address.
52+
incentives_address = '{{ gateway.incentives_address }}'
53+
5154
# Validator server to which the node will be reporting their presence data.
5255
validator_rest_url = '{{ gateway.validator_rest_url }}'
5356

gateway/src/node/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ impl Gateway {
194194
self.encryption_keys.public_key().to_base58_string(),
195195
self.config.get_version().to_string(),
196196
self.config.get_location(),
197+
self.config.get_incentives_address()
197198
).await {
198199
error!("failed to register with the validator - {:?}", err);
199200
return

gateway/src/node/presence.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) async fn register_with_validator(
2525
sphinx_key: String,
2626
version: String,
2727
location: String,
28+
incentives_address: Option<String>,
2829
) -> Result<(), ValidatorClientError> {
2930
let config = validator_client::Config::new(validator_endpoint);
3031
let validator_client = validator_client::Client::new(config);
@@ -36,6 +37,7 @@ pub(crate) async fn register_with_validator(
3637
sphinx_key,
3738
version,
3839
location,
40+
incentives_address,
3941
);
4042

4143
validator_client.register_gateway(registration_info).await

mixnode/src/commands/init.rs

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
8282
.help("Server to which the node is sending all metrics data")
8383
.takes_value(true),
8484
)
85+
.arg(
86+
Arg::with_name("incentives-address")
87+
.long("incentives-address")
88+
.help("Optional, if participating in the incentives program, payment address")
89+
.takes_value(true),
90+
)
8591
}
8692

8793
fn show_incentives_url() {

mixnode/src/commands/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,9 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi
7777
config = config.with_location(location);
7878
}
7979

80+
if let Some(incentives_address) = matches.value_of("incentives-address") {
81+
config = config.with_incentives_address(incentives_address);
82+
}
83+
8084
config
8185
}

mixnode/src/config/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ where
131131
deserializer.deserialize_any(DurationVisitor)
132132
}
133133

134+
fn deserialize_option_string<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
135+
where
136+
D: Deserializer<'de>,
137+
{
138+
let s = String::deserialize(deserializer)?;
139+
if s.is_empty() {
140+
Ok(None)
141+
} else {
142+
Ok(Some(s))
143+
}
144+
}
145+
134146
pub fn missing_string_value<T: From<String>>() -> T {
135147
MISSING_VALUE.to_string().into()
136148
}
@@ -270,6 +282,11 @@ impl Config {
270282
self
271283
}
272284

285+
pub fn with_incentives_address<S: Into<String>>(mut self, incentives_address: S) -> Self {
286+
self.mixnode.incentives_address = Some(incentives_address.into());
287+
self
288+
}
289+
273290
// getters
274291
pub fn get_config_file_save_location(&self) -> PathBuf {
275292
self.config_directory().join(Self::config_file_name())
@@ -343,6 +360,10 @@ impl Config {
343360
&self.mixnode.version
344361
}
345362

363+
pub fn get_incentives_address(&self) -> Option<String> {
364+
self.mixnode.incentives_address.clone()
365+
}
366+
346367
// upgrade-specific
347368
pub(crate) fn set_default_identity_keypair_paths(&mut self) {
348369
self.mixnode.private_identity_key_file =
@@ -406,6 +427,10 @@ pub struct MixNode {
406427
/// nym_home_directory specifies absolute path to the home nym MixNodes directory.
407428
/// It is expected to use default value and hence .toml file should not redefine this field.
408429
nym_root_directory: PathBuf,
430+
431+
/// Optional, if participating in the incentives program, payment address.
432+
#[serde(deserialize_with = "deserialize_option_string")]
433+
incentives_address: Option<String>,
409434
}
410435

411436
impl MixNode {
@@ -448,6 +473,7 @@ impl Default for MixNode {
448473
validator_rest_url: DEFAULT_VALIDATOR_REST_ENDPOINT.to_string(),
449474
metrics_server_url: DEFAULT_METRICS_SERVER.to_string(),
450475
nym_root_directory: Config::default_root_directory(),
476+
incentives_address: None,
451477
}
452478
}
453479
}

mixnode/src/config/template.rs

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ private_sphinx_key_file = '{{ mixnode.private_sphinx_key_file }}'
5454
# Path to file containing public sphinx key.
5555
public_sphinx_key_file = '{{ mixnode.public_sphinx_key_file }}'
5656
57+
# Optional, if participating in the incentives program, payment address.
58+
incentives_address = '{{ mixnode.incentives_address }}'
59+
5760
##### additional mixnode config options #####
5861
5962
# Optional address announced to the directory server for the clients to connect to.

mixnode/src/node/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl MixNode {
152152
self.config.get_version().to_string(),
153153
self.config.get_location(),
154154
self.config.get_layer(),
155+
self.config.get_incentives_address(),
155156
).await {
156157
error!("failed to register with the validator - {:?}", err);
157158
return

mixnode/src/node/presence.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ pub(crate) async fn register_with_validator(
2525
version: String,
2626
location: String,
2727
layer: u64,
28+
incentives_address: Option<String>,
2829
) -> Result<(), ValidatorClientError> {
2930
let config = validator_client::Config::new(validator_endpoint);
3031
let validator_client = validator_client::Client::new(config);
3132

32-
let registration_info =
33-
MixRegistrationInfo::new(mix_host, identity_key, sphinx_key, version, location, layer);
33+
let registration_info = MixRegistrationInfo::new(
34+
mix_host,
35+
identity_key,
36+
sphinx_key,
37+
version,
38+
location,
39+
layer,
40+
incentives_address,
41+
);
3442

3543
validator_client.register_mix(registration_info).await
3644
}

0 commit comments

Comments
 (0)