@@ -4,7 +4,6 @@ use std::{
4
4
time:: Duration ,
5
5
} ;
6
6
7
- use multi_index_map:: MultiIndexMap ;
8
7
use once_cell:: sync:: OnceCell ;
9
8
use openssl:: { pkey:: Public , rsa:: Rsa } ;
10
9
use r2d2_sqlite:: SqliteConnectionManager ;
@@ -19,64 +18,16 @@ use tokio::sync::{
19
18
} ;
20
19
use types:: { Address , PublicKeyBytes } ;
21
20
22
- pub use crate :: { error:: DatabaseError , state:: NetworkState } ;
23
-
24
- /// All the shares that belong to the current operator.
25
- /// IMPORTANT: There are parts of the code that assume this only contains shares that belong to the
26
- /// current operator. If this ever changes, make sure to update the code accordingly.
27
- #[ derive( Debug , Clone , MultiIndexMap ) ]
28
- pub struct ShareIndexed {
29
- #[ multi_index( hashed_unique) ]
30
- pub validator_pubkey : PublicKeyBytes ,
31
-
32
- #[ multi_index( hashed_non_unique) ]
33
- pub cluster_id : ClusterId ,
34
-
35
- #[ multi_index( hashed_non_unique) ]
36
- pub owner : Address ,
37
-
38
- #[ multi_index( hashed_non_unique) ]
39
- pub committee_id : CommitteeId ,
40
-
41
- pub share : Share ,
42
- }
43
-
44
- /// Metadata for all validators in the network
45
- #[ derive( Debug , Clone , MultiIndexMap ) ]
46
- pub struct MetadataIndexed {
47
- #[ multi_index( hashed_unique) ]
48
- pub validator_pubkey : PublicKeyBytes ,
49
-
50
- #[ multi_index( hashed_non_unique) ]
51
- pub cluster_id : ClusterId ,
52
-
53
- #[ multi_index( hashed_non_unique) ]
54
- pub owner : Address ,
55
-
56
- #[ multi_index( hashed_non_unique) ]
57
- pub committee_id : CommitteeId ,
58
-
59
- pub metadata : ValidatorMetadata ,
60
- }
61
-
62
- /// All the clusters in the network
63
- #[ derive( Debug , Clone , MultiIndexMap ) ]
64
- pub struct ClusterIndexed {
65
- #[ multi_index( hashed_unique) ]
66
- pub cluster_id : ClusterId ,
67
-
68
- #[ multi_index( hashed_non_unique) ]
69
- pub owner : Address ,
70
-
71
- #[ multi_index( hashed_non_unique) ]
72
- pub committee_id : CommitteeId ,
73
-
74
- pub cluster : Cluster ,
75
- }
21
+ pub use crate :: {
22
+ error:: DatabaseError ,
23
+ multi_index:: { MultiIndexMap , * } ,
24
+ state:: NetworkState ,
25
+ } ;
76
26
77
27
mod cluster_operations;
78
28
mod error;
79
29
mod keysplit_operations;
30
+ mod multi_index;
80
31
mod operator_operations;
81
32
mod schema;
82
33
mod share_operations;
@@ -93,16 +44,57 @@ const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5);
93
44
type Pool = r2d2:: Pool < SqliteConnectionManager > ;
94
45
type PoolConn = r2d2:: PooledConnection < SqliteConnectionManager > ;
95
46
96
- // The actual map types are generated by the macro and are named:
97
- // - MultiIndexShareIndexedMap
98
- // - MultiIndexMetadataIndexedMap
99
- // - MultiIndexClusterIndexedMap
100
- //
101
- // Information that needs to be accessed via multiple different indices
47
+ /// All the shares that belong to the current operator.
48
+ /// IMPORTANT: There are parts of the code that assume this only contains shares that belong to the
49
+ /// current operator. If this ever changes, make sure to update the code accordingly.
50
+ /// Primary: public key of validator, uniquely identifies a share
51
+ /// Secondary: cluster id, corresponds to a list of shares
52
+ /// Tertiary: owner of the cluster, corresponds to a list of shares
53
+ pub type ShareMultiIndexMap = MultiIndexMap <
54
+ PublicKeyBytes ,
55
+ ClusterId ,
56
+ Address ,
57
+ CommitteeId ,
58
+ Share ,
59
+ NonUniqueTag ,
60
+ NonUniqueTag ,
61
+ NonUniqueTag ,
62
+ > ;
63
+ /// Metadata for all validators in the network
64
+ /// Primary: public key of the validator. uniquely identifies the metadata
65
+ /// Secondary: cluster id. corresponds to list of metadata for all validators
66
+ /// Tertiary: owner of the cluster: corresponds to list of metadata for all validators
67
+ pub type MetadataMultiIndexMap = MultiIndexMap <
68
+ PublicKeyBytes ,
69
+ ClusterId ,
70
+ Address ,
71
+ CommitteeId ,
72
+ ValidatorMetadata ,
73
+ NonUniqueTag ,
74
+ NonUniqueTag ,
75
+ NonUniqueTag ,
76
+ > ;
77
+ /// All of the clusters in the network
78
+ /// Primary: cluster id. uniquely identifies a cluster
79
+ /// Secondary: public key of the validator. uniquely identifies a cluster
80
+ /// Tertiary: owner of the cluster. does not uniquely identify a cluster
81
+ pub type ClusterMultiIndexMap = MultiIndexMap <
82
+ ClusterId ,
83
+ PublicKeyBytes ,
84
+ Address ,
85
+ CommitteeId ,
86
+ Cluster ,
87
+ UniqueTag ,
88
+ NonUniqueTag ,
89
+ NonUniqueTag ,
90
+ > ;
91
+
92
+ // Information that needs to be accessed via multiple different indicies
93
+ #[ derive( Debug ) ]
102
94
struct MultiState {
103
- shares : MultiIndexShareIndexedMap ,
104
- validator_metadata : MultiIndexMetadataIndexedMap ,
105
- clusters : MultiIndexClusterIndexedMap ,
95
+ shares : ShareMultiIndexMap ,
96
+ validator_metadata : MetadataMultiIndexMap ,
97
+ clusters : ClusterMultiIndexMap ,
106
98
// Be careful when adding new maps here. If you really must to, it must be updated in the
107
99
// operations files
108
100
}
@@ -132,6 +124,7 @@ enum PubkeyOrId {
132
124
133
125
/// Top level NetworkDatabase that contains in memory storage for quick access
134
126
/// to relevant information and a connection to the database
127
+ #[ derive( Debug ) ]
135
128
pub struct NetworkDatabase {
136
129
/// The public key or ID of our operator
137
130
operator : PubkeyOrId ,
0 commit comments