1
- use std:: {
2
- collections:: { HashMap , HashSet } ,
3
- io:: Write ,
4
- path:: PathBuf ,
5
- } ;
1
+ use std:: { collections:: HashMap , io:: Write , path:: PathBuf } ;
6
2
7
3
use alloy:: { hex, rpc:: types:: beacon:: constants:: BLS_SIGNATURE_BYTES_LEN } ;
8
4
use blsful:: inner_types:: { Field , G2Affine , G2Projective , Group , Scalar } ;
@@ -37,10 +33,10 @@ enum Account {
37
33
}
38
34
39
35
impl Account {
40
- pub fn full_name ( & self ) -> String {
36
+ pub fn name ( & self ) -> & str {
41
37
match self {
42
- Account :: Simple ( account) => format ! ( "{}/{}" , account. wallet , account . name) ,
43
- Account :: Distributed ( account) => format ! ( "{}/{}" , account. wallet , account . name) ,
38
+ Account :: Simple ( account) => & account. name ,
39
+ Account :: Distributed ( account) => & account. name ,
44
40
}
45
41
}
46
42
}
@@ -49,7 +45,6 @@ impl Account {
49
45
struct SimpleAccount {
50
46
public_key : BlsPublicKey ,
51
47
connection : Channel ,
52
- wallet : String ,
53
48
name : String ,
54
49
}
55
50
@@ -58,7 +53,6 @@ struct DistributedAccount {
58
53
composite_public_key : BlsPublicKey ,
59
54
participants : HashMap < u32 , Channel > ,
60
55
threshold : u32 ,
61
- wallet : String ,
62
56
name : String ,
63
57
}
64
58
@@ -107,14 +101,8 @@ impl DirkManager {
107
101
}
108
102
} ;
109
103
110
- let wallets: HashSet < String > = host
111
- . accounts
112
- . iter ( )
113
- . map ( |account| decompose_name ( account) . unwrap_or_default ( ) . 0 )
114
- . collect ( ) ;
115
-
116
104
let accounts_response = match ListerClient :: new ( channel. clone ( ) )
117
- . list_accounts ( ListAccountsRequest { paths : wallets. into_iter ( ) . collect ( ) } )
105
+ . list_accounts ( ListAccountsRequest { paths : host . wallets . clone ( ) } )
118
106
. await
119
107
{
120
108
Ok ( res) => res,
@@ -130,12 +118,7 @@ impl DirkManager {
130
118
}
131
119
132
120
let accounts_response = accounts_response. into_inner ( ) ;
133
- load_simple_accounts (
134
- accounts_response. accounts ,
135
- & host,
136
- & channel,
137
- & mut consensus_accounts,
138
- ) ;
121
+ load_simple_accounts ( accounts_response. accounts , & channel, & mut consensus_accounts) ;
139
122
load_distributed_accounts (
140
123
accounts_response. distributed_accounts ,
141
124
& host,
@@ -144,15 +127,6 @@ impl DirkManager {
144
127
)
145
128
. map_err ( |error| warn ! ( "{error}" ) )
146
129
. ok ( ) ;
147
-
148
- for account in host. accounts {
149
- if !consensus_accounts
150
- . values ( )
151
- . any ( |account| account. full_name ( ) == account. full_name ( ) )
152
- {
153
- warn ! ( "Account {account} not found in server {}" , host. url) ;
154
- }
155
- }
156
130
}
157
131
158
132
debug ! (
@@ -293,10 +267,7 @@ impl DirkManager {
293
267
. sign ( SignRequest {
294
268
data : object_root. to_vec ( ) ,
295
269
domain : compute_domain ( self . chain , COMMIT_BOOST_DOMAIN ) . to_vec ( ) ,
296
- id : Some ( sign_request:: Id :: Account ( format ! (
297
- "{}/{}" ,
298
- account. wallet, account. name
299
- ) ) ) ,
270
+ id : Some ( sign_request:: Id :: Account ( account. name . clone ( ) ) ) ,
300
271
} )
301
272
. map ( |res| ( res, * id) )
302
273
. await
@@ -392,7 +363,7 @@ impl DirkManager {
392
363
393
364
let response = AccountManagerClient :: new ( consensus. connection . clone ( ) )
394
365
. generate ( GenerateRequest {
395
- account : format ! ( "{}/{}/{ module}/{uuid}" , consensus . wallet , consensus. name) ,
366
+ account : format ! ( "{}/{module}/{uuid}" , consensus. name) ,
396
367
passphrase : password. as_bytes ( ) . to_vec ( ) ,
397
368
participants : 1 ,
398
369
signing_threshold : 1 ,
@@ -418,7 +389,6 @@ impl DirkManager {
418
389
inner : Account :: Simple ( SimpleAccount {
419
390
public_key : proxy_key,
420
391
connection : consensus. connection . clone ( ) ,
421
- wallet : consensus. wallet . clone ( ) ,
422
392
name : format ! ( "{}/{module}/{uuid}" , consensus. name) ,
423
393
} ) ,
424
394
} ;
@@ -450,7 +420,7 @@ impl DirkManager {
450
420
for ( id, channel) in consensus. participants . iter ( ) {
451
421
let Ok ( response) = AccountManagerClient :: new ( channel. clone ( ) )
452
422
. generate ( GenerateRequest {
453
- account : format ! ( "{}/{}/{ module}/{uuid}" , consensus . wallet , consensus. name) ,
423
+ account : format ! ( "{}/{module}/{uuid}" , consensus. name) ,
454
424
passphrase : password. as_bytes ( ) . to_vec ( ) ,
455
425
participants : consensus. participants . len ( ) as u32 ,
456
426
signing_threshold : consensus. threshold ,
@@ -479,7 +449,6 @@ impl DirkManager {
479
449
composite_public_key : proxy_key,
480
450
participants : consensus. participants . clone ( ) ,
481
451
threshold : consensus. threshold ,
482
- wallet : consensus. wallet . clone ( ) ,
483
452
name : format ! ( "{}/{module}/{uuid}" , consensus. name) ,
484
453
} ) ,
485
454
} ;
@@ -506,8 +475,8 @@ impl DirkManager {
506
475
507
476
/// Store the password for a proxy account in disk
508
477
fn store_password ( & self , account : & ProxyAccount , password : String ) -> eyre:: Result < ( ) > {
509
- let full_name = account. inner . full_name ( ) ;
510
- let ( parent, name) = full_name . rsplit_once ( '/' ) . ok_or_eyre ( "Invalid account name" ) ?;
478
+ let name = account. inner . name ( ) ;
479
+ let ( parent, name) = name . rsplit_once ( '/' ) . ok_or_eyre ( "Invalid account name" ) ?;
511
480
let parent_path = self . secrets_path . join ( parent) ;
512
481
513
482
std:: fs:: create_dir_all ( parent_path. clone ( ) ) ?;
@@ -530,7 +499,7 @@ impl DirkManager {
530
499
let request = async move {
531
500
let response = AccountManagerClient :: new ( channel. clone ( ) )
532
501
. unlock ( UnlockAccountRequest {
533
- account : account. full_name ( ) ,
502
+ account : account. name ( ) . to_string ( ) ,
534
503
passphrase : password. as_bytes ( ) . to_vec ( ) ,
535
504
} )
536
505
. await ;
@@ -584,40 +553,26 @@ async fn connect(
584
553
. map_err ( eyre:: Error :: from)
585
554
}
586
555
587
- /// Decompose a full account name into wallet and name
588
- fn decompose_name ( full_name : & str ) -> eyre:: Result < ( String , String ) > {
589
- full_name
590
- . split_once ( '/' )
591
- . map ( |( wallet, name) | ( wallet. to_string ( ) , name. to_string ( ) ) )
592
- . ok_or_else ( || eyre:: eyre!( "Invalid account name" ) )
593
- }
594
-
595
556
/// Load `SimpleAccount`s into the consensus accounts map
596
557
fn load_simple_accounts (
597
558
accounts : Vec < crate :: proto:: v1:: Account > ,
598
- host : & DirkHostConfig ,
599
559
channel : & Channel ,
600
560
consensus_accounts : & mut HashMap < BlsPublicKey , Account > ,
601
561
) {
602
562
for account in accounts {
603
- if !host. accounts . contains ( & account. name ) {
563
+ if name_matches_proxy ( & account. name ) {
564
+ debug ! ( account = account. name, "Ignoring account assuming it's a proxy key" ) ;
604
565
continue ;
605
566
}
606
567
607
- let Ok ( ( wallet, name) ) = decompose_name ( & account. name ) else {
608
- warn ! ( "Invalid account name {}" , account. name) ;
609
- continue ;
610
- } ;
611
-
612
568
match BlsPublicKey :: try_from ( account. public_key . as_slice ( ) ) {
613
569
Ok ( public_key) => {
614
570
consensus_accounts. insert (
615
571
public_key,
616
572
Account :: Simple ( SimpleAccount {
617
573
public_key,
618
574
connection : channel. clone ( ) ,
619
- wallet,
620
- name,
575
+ name : account. name ,
621
576
} ) ,
622
577
) ;
623
578
}
@@ -643,7 +598,8 @@ fn load_distributed_accounts(
643
598
. ok_or ( eyre:: eyre!( "Host name not found for server {}" , host. url) ) ?;
644
599
645
600
for account in accounts {
646
- if !host. accounts . contains ( & account. name ) {
601
+ if name_matches_proxy ( & account. name ) {
602
+ debug ! ( account = account. name, "Ignoring account assuming it's a proxy key" ) ;
647
603
continue ;
648
604
}
649
605
@@ -677,11 +633,6 @@ fn load_distributed_accounts(
677
633
}
678
634
}
679
635
None => {
680
- let Ok ( ( wallet, name) ) = decompose_name ( & account. name ) else {
681
- warn ! ( "Invalid account name {}" , account. name) ;
682
- continue ;
683
- } ;
684
-
685
636
let mut participants = HashMap :: with_capacity ( account. participants . len ( ) ) ;
686
637
participants. insert ( participant_id as u32 , channel. clone ( ) ) ;
687
638
@@ -691,8 +642,7 @@ fn load_distributed_accounts(
691
642
composite_public_key : public_key,
692
643
participants,
693
644
threshold : account. signing_threshold ,
694
- wallet,
695
- name,
645
+ name : account. name ,
696
646
} ) ,
697
647
) ;
698
648
}
@@ -752,6 +702,14 @@ fn random_password() -> String {
752
702
hex:: encode ( password_bytes)
753
703
}
754
704
705
+ /// Returns whether the name of an account has a proxy name format.
706
+ ///
707
+ /// i.e., `{wallet}/{consensus_proxy}/{module}/{uuid}`
708
+ fn name_matches_proxy ( name : & str ) -> bool {
709
+ name. split ( "/" ) . count ( ) > 3 &&
710
+ name. rsplit_once ( "/" ) . is_some_and ( |( _, name) | uuid:: Uuid :: parse_str ( name) . is_ok ( ) )
711
+ }
712
+
755
713
mod test {
756
714
757
715
#[ test]
0 commit comments