@@ -136,7 +136,8 @@ async fn main() -> eyre::Result<()> {
136136 let bootnodes = read_bootnodes ( & bootnodes_path) ;
137137
138138 let validator_keys =
139- read_validator_keys ( & validators_path, & validator_keys_dir, & options. node_id ) ;
139+ read_validator_keys ( & validators_path, & validator_keys_dir, & options. node_id )
140+ . expect ( "Failed to load validator keys" ) ;
140141
141142 let data_dir =
142143 std:: path:: absolute ( & options. data_dir ) . unwrap_or_else ( |_| options. data_dir . clone ( ) ) ;
@@ -238,12 +239,6 @@ fn read_bootnodes(bootnodes_path: impl AsRef<Path>) -> Vec<Bootnode> {
238239#[ derive( Debug , Deserialize ) ]
239240struct AnnotatedValidator {
240241 index : u64 ,
241- #[ serde( rename = "attestation_pubkey_hex" ) ]
242- #[ serde( deserialize_with = "deser_pubkey_hex" ) ]
243- _attestation_pubkey : ValidatorPubkeyBytes ,
244- #[ serde( rename = "proposal_pubkey_hex" ) ]
245- #[ serde( deserialize_with = "deser_pubkey_hex" ) ]
246- _proposal_pubkey : ValidatorPubkeyBytes ,
247242 attestation_privkey_file : PathBuf ,
248243 proposal_privkey_file : PathBuf ,
249244}
@@ -266,17 +261,18 @@ fn read_validator_keys(
266261 validators_path : impl AsRef < Path > ,
267262 validator_keys_dir : impl AsRef < Path > ,
268263 node_id : & str ,
269- ) -> HashMap < u64 , ValidatorKeyPair > {
264+ ) -> Result < HashMap < u64 , ValidatorKeyPair > , String > {
270265 let validators_path = validators_path. as_ref ( ) ;
271266 let validator_keys_dir = validator_keys_dir. as_ref ( ) ;
272- let validators_yaml =
273- std :: fs :: read_to_string ( validators_path ) . expect ( "Failed to read validators file" ) ;
267+ let validators_yaml = std :: fs :: read_to_string ( validators_path )
268+ . map_err ( |err| format ! ( "Failed to read validators file: {err}" ) ) ? ;
274269 let validator_infos: BTreeMap < String , Vec < AnnotatedValidator > > =
275- serde_yaml_ng:: from_str ( & validators_yaml) . expect ( "Failed to parse validators file" ) ;
270+ serde_yaml_ng:: from_str ( & validators_yaml)
271+ . map_err ( |err| format ! ( "Failed to parse validators file: {err}" ) ) ?;
276272
277273 let validator_vec = validator_infos
278274 . get ( node_id)
279- . unwrap_or_else ( || panic ! ( "Node ID '{}' not found in validators config" , node_id ) ) ;
275+ . ok_or_else ( || format ! ( "Node ID '{node_id }' not found in validators config" ) ) ? ;
280276
281277 let mut validator_keys = HashMap :: new ( ) ;
282278
@@ -294,21 +290,21 @@ fn read_validator_keys(
294290 let att_key_path = resolve_path ( & validator. attestation_privkey_file ) ;
295291 let prop_key_path = resolve_path ( & validator. proposal_privkey_file ) ;
296292
297- info ! ( node_id= %node_id, index=validator_index, attestation_key=?att_key_path, proposal_key=?prop_key_path, "Loading validator key pair" ) ;
298-
299- let load_key = |path : & Path , purpose : & str | -> ValidatorSecretKey {
300- let bytes = std:: fs:: read ( path) . unwrap_or_else ( |err| {
301- error ! ( node_id=%node_id , index=validator_index , file=?path , %err , "Failed to read {purpose} key file" ) ;
302- std :: process :: exit ( 1 ) ;
303- } ) ;
304- ValidatorSecretKey :: from_bytes ( & bytes ) . unwrap_or_else ( |err| {
305- error ! ( node_id=%node_id , index=validator_index , file=?path , ?err , "Failed to parse {purpose} key" ) ;
306- std :: process :: exit ( 1 ) ;
307- } )
293+ info ! ( %node_id, index=validator_index, attestation_key=?att_key_path, proposal_key=?prop_key_path, "Loading validator key pair" ) ;
294+
295+ let load_key = |path : & Path , purpose : & str | -> Result < ValidatorSecretKey , String > {
296+ let bytes = std:: fs:: read ( path) . map_err ( |err| {
297+ format ! (
298+ "Failed to read {purpose} key file {}: {err}" ,
299+ path . display ( )
300+ )
301+ } ) ? ;
302+ ValidatorSecretKey :: from_bytes ( & bytes )
303+ . map_err ( |err| format ! ( "Failed to parse {purpose} key {}: {err:?}" , path . display ( ) ) )
308304 } ;
309305
310- let attestation_key = load_key ( & att_key_path, "attestation" ) ;
311- let proposal_key = load_key ( & prop_key_path, "proposal" ) ;
306+ let attestation_key = load_key ( & att_key_path, "attestation" ) ? ;
307+ let proposal_key = load_key ( & prop_key_path, "proposal" ) ? ;
312308
313309 validator_keys. insert (
314310 validator_index,
@@ -320,12 +316,12 @@ fn read_validator_keys(
320316 }
321317
322318 info ! (
323- node_id = %node_id,
319+ %node_id,
324320 count = validator_keys. len( ) ,
325321 "Loaded validator key pairs"
326322 ) ;
327323
328- validator_keys
324+ Ok ( validator_keys)
329325}
330326
331327fn read_hex_file_bytes ( path : impl AsRef < Path > ) -> Vec < u8 > {
0 commit comments