Skip to content

Commit 6cdc908

Browse files
committed
Add merge messages to one file
1 parent 5a4f928 commit 6cdc908

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

lighthouse/tests/validator_manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ pub fn validator_exit_defaults() {
503503
beacon_url: Some(SensitiveUrl::parse("http://localhost:5052").unwrap()),
504504
exit_epoch: None,
505505
signature: false,
506+
merge: false,
506507
exit_status: false,
507508
};
508509
assert_eq!(expected, config);

validator_manager/src/exit_validators.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub const VALIDATOR_FLAG: &str = "validators";
1919
pub const EXIT_EPOCH_FLAG: &str = "exit-epoch";
2020
pub const SIGNATURE_FLAG: &str = "signature";
2121
pub const EXIT_STATUS_FLAG: &str = "status";
22+
pub const MERGE_FLAG: &str = "merge";
2223

2324
pub fn cli_app() -> Command {
2425
Command::new(CMD)
@@ -68,16 +69,37 @@ pub fn cli_app() -> Command {
6869
Arg::new(EXIT_EPOCH_FLAG)
6970
.long(EXIT_EPOCH_FLAG)
7071
.value_name("EPOCH")
71-
.help("Provide the minimum epoch for processing voluntary exit.")
72+
.help(
73+
"Provide the minimum epoch for processing voluntary exit. \
74+
This flag is typically used in combination with `--signature` to \
75+
save the voluntary exit signature to a file for future use.",
76+
)
7277
.action(ArgAction::Set)
7378
.display_order(0),
7479
)
7580
.arg(
7681
Arg::new(SIGNATURE_FLAG)
7782
.long(SIGNATURE_FLAG)
78-
.help("Display the signature of the voluntary exit.")
83+
.help(
84+
"Generate the voluntary exit signature and save it to a file \
85+
named {validator_pubkey}.json. Note: Using this without the \
86+
`--beacon-node` flag will not publish the voluntary exit to the network.",
87+
)
88+
.help_heading(FLAG_HEADER)
89+
.action(ArgAction::SetTrue)
90+
.display_order(0),
91+
)
92+
.arg(
93+
Arg::new(MERGE_FLAG)
94+
.long(MERGE_FLAG)
95+
.help(
96+
"Merge the generated voluntary exit signatures into a single file named \
97+
`all_validators.json`. This flag has to be used together with \
98+
the `--signature` flag.",
99+
)
79100
.help_heading(FLAG_HEADER)
80101
.action(ArgAction::SetTrue)
102+
.requires(SIGNATURE_FLAG)
81103
.display_order(0),
82104
)
83105
.arg(
@@ -99,6 +121,7 @@ pub struct ExitConfig {
99121
pub beacon_url: Option<SensitiveUrl>,
100122
pub exit_epoch: Option<Epoch>,
101123
pub signature: bool,
124+
pub merge: bool,
102125
pub exit_status: bool,
103126
}
104127

@@ -123,6 +146,7 @@ impl ExitConfig {
123146
beacon_url: clap_utils::parse_optional(matches, BEACON_URL_FLAG)?,
124147
exit_epoch: clap_utils::parse_optional(matches, EXIT_EPOCH_FLAG)?,
125148
signature: matches.get_flag(SIGNATURE_FLAG),
149+
merge: matches.get_flag(MERGE_FLAG),
126150
exit_status: matches.get_flag(EXIT_STATUS_FLAG),
127151
})
128152
}
@@ -149,6 +173,7 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
149173
beacon_url,
150174
exit_epoch,
151175
signature,
176+
merge,
152177
exit_status,
153178
} = config;
154179

@@ -158,6 +183,8 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
158183
validators_to_exit = validators.iter().map(|v| v.validating_pubkey).collect();
159184
}
160185

186+
let mut exit_message_all = Vec::new();
187+
161188
for validator_to_exit in validators_to_exit {
162189
// Check that the validators_to_exit is in the validator client
163190
if !validators
@@ -174,13 +201,18 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
174201

175202
if signature {
176203
let exit_message_json = serde_json::to_string(&exit_message.data);
204+
177205
match exit_message_json {
178206
Ok(json) => {
179-
// Save the exit message to a JSON file
180-
let file_path = format!("validator_{}.json", validator_to_exit);
181-
std::fs::write(&file_path, json)
182-
.map_err(|e| format!("Failed to write exit message to file: {}", e))?;
183-
println!("Exit message saved to {}", file_path);
207+
// Save the exit message to JSON file(s)
208+
if merge {
209+
exit_message_all.push(json.clone());
210+
} else {
211+
let file_path = format!("{}.json", validator_to_exit);
212+
std::fs::write(&file_path, json)
213+
.map_err(|e| format!("Failed to write voluntary exit message to file: {}", e))?;
214+
println!("Voluntary exit message saved to {}", file_path);
215+
}
184216
}
185217
Err(e) => eprintln!("Failed to serialize voluntary exit message: {}", e),
186218
}
@@ -324,6 +356,14 @@ async fn run<E: EthSpec>(config: ExitConfig) -> Result<(), String> {
324356
}
325357
}
326358
}
359+
360+
if merge {
361+
let all_json = serde_json::to_string(&exit_message_all)
362+
.map_err(|e| format!("Failed to serialize voluntary exit message: {}", e))?;
363+
std::fs::write("all_validators.json", all_json)
364+
.map_err(|e| format!("Failed to write all voluntary exit messages to file: {}", e))?;
365+
println!("All voluntary exit messages save to all_validators.json.")
366+
}
327367
Ok(())
328368
}
329369

@@ -484,6 +524,7 @@ mod test {
484524
beacon_url: Some(beacon_url),
485525
exit_epoch: None,
486526
signature: false,
527+
merge: false,
487528
exit_status: false,
488529
});
489530

0 commit comments

Comments
 (0)