@@ -6,8 +6,8 @@ use slog::error;
6
6
use slog:: warn;
7
7
use slog:: Logger ;
8
8
9
- use crate :: components:: network_provider:: ChainIdentifierStore ;
10
- use crate :: components:: network_provider:: ChainIdentifierStoreError ;
9
+ use crate :: components:: network_provider:: ChainIdentifierValidationError ;
10
+ use crate :: components:: network_provider:: ChainIdentifierValidator ;
11
11
use crate :: components:: network_provider:: ChainName ;
12
12
use crate :: components:: network_provider:: NetworkDetails ;
13
13
use crate :: components:: network_provider:: ProviderCheck ;
@@ -17,11 +17,11 @@ use crate::components::network_provider::ProviderName;
17
17
/// Requires providers to have the same network version and genesis hash as one
18
18
/// previously stored in the database.
19
19
pub struct GenesisHashCheck {
20
- chain_identifier_store : Arc < dyn ChainIdentifierStore > ,
20
+ chain_identifier_store : Arc < dyn ChainIdentifierValidator > ,
21
21
}
22
22
23
23
impl GenesisHashCheck {
24
- pub fn new ( chain_identifier_store : Arc < dyn ChainIdentifierStore > ) -> Self {
24
+ pub fn new ( chain_identifier_store : Arc < dyn ChainIdentifierValidator > ) -> Self {
25
25
Self {
26
26
chain_identifier_store,
27
27
}
@@ -62,7 +62,7 @@ impl ProviderCheck for GenesisHashCheck {
62
62
. chain_identifier_store
63
63
. validate_identifier ( chain_name, & chain_identifier) ;
64
64
65
- use ChainIdentifierStoreError :: * ;
65
+ use ChainIdentifierValidationError :: * ;
66
66
67
67
match check_result {
68
68
Ok ( ( ) ) => ProviderCheckStatus :: Valid ,
@@ -154,16 +154,16 @@ mod tests {
154
154
155
155
#[ derive( Default ) ]
156
156
struct TestChainIdentifierStore {
157
- validate_identifier_calls : Mutex < Vec < Result < ( ) , ChainIdentifierStoreError > > > ,
158
- update_identifier_calls : Mutex < Vec < Result < ( ) , ChainIdentifierStoreError > > > ,
157
+ validate_identifier_calls : Mutex < Vec < Result < ( ) , ChainIdentifierValidationError > > > ,
158
+ update_identifier_calls : Mutex < Vec < Result < ( ) , ChainIdentifierValidationError > > > ,
159
159
}
160
160
161
161
impl TestChainIdentifierStore {
162
- fn validate_identifier_call ( & self , x : Result < ( ) , ChainIdentifierStoreError > ) {
162
+ fn validate_identifier_call ( & self , x : Result < ( ) , ChainIdentifierValidationError > ) {
163
163
self . validate_identifier_calls . lock ( ) . unwrap ( ) . push ( x)
164
164
}
165
165
166
- fn update_identifier_call ( & self , x : Result < ( ) , ChainIdentifierStoreError > ) {
166
+ fn update_identifier_call ( & self , x : Result < ( ) , ChainIdentifierValidationError > ) {
167
167
self . update_identifier_calls . lock ( ) . unwrap ( ) . push ( x)
168
168
}
169
169
}
@@ -181,20 +181,20 @@ mod tests {
181
181
}
182
182
183
183
#[ async_trait]
184
- impl ChainIdentifierStore for TestChainIdentifierStore {
184
+ impl ChainIdentifierValidator for TestChainIdentifierStore {
185
185
fn validate_identifier (
186
186
& self ,
187
187
_chain_name : & ChainName ,
188
188
_chain_identifier : & ChainIdentifier ,
189
- ) -> Result < ( ) , ChainIdentifierStoreError > {
189
+ ) -> Result < ( ) , ChainIdentifierValidationError > {
190
190
self . validate_identifier_calls . lock ( ) . unwrap ( ) . remove ( 0 )
191
191
}
192
192
193
193
fn update_identifier (
194
194
& self ,
195
195
_chain_name : & ChainName ,
196
196
_chain_identifier : & ChainIdentifier ,
197
- ) -> Result < ( ) , ChainIdentifierStoreError > {
197
+ ) -> Result < ( ) , ChainIdentifierValidationError > {
198
198
self . update_identifier_calls . lock ( ) . unwrap ( ) . remove ( 0 )
199
199
}
200
200
}
@@ -288,10 +288,10 @@ mod tests {
288
288
#[ tokio:: test]
289
289
async fn check_temporary_failure_on_initial_chain_identifier_update_error ( ) {
290
290
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
291
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: IdentifierNotSet (
291
+ store. validate_identifier_call ( Err ( ChainIdentifierValidationError :: IdentifierNotSet (
292
292
"chain-1" . into ( ) ,
293
293
) ) ) ;
294
- store. update_identifier_call ( Err ( ChainIdentifierStoreError :: Store ( anyhow ! ( "error" ) ) ) ) ;
294
+ store. update_identifier_call ( Err ( ChainIdentifierValidationError :: Store ( anyhow ! ( "error" ) ) ) ) ;
295
295
296
296
let check = GenesisHashCheck :: new ( store) ;
297
297
@@ -321,7 +321,7 @@ mod tests {
321
321
#[ tokio:: test]
322
322
async fn check_valid_on_initial_chain_identifier_update ( ) {
323
323
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
324
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: IdentifierNotSet (
324
+ store. validate_identifier_call ( Err ( ChainIdentifierValidationError :: IdentifierNotSet (
325
325
"chain-1" . into ( ) ,
326
326
) ) ) ;
327
327
store. update_identifier_call ( Ok ( ( ) ) ) ;
@@ -351,7 +351,7 @@ mod tests {
351
351
#[ tokio:: test]
352
352
async fn check_valid_when_stored_identifier_network_version_is_zero ( ) {
353
353
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
354
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: NetVersionMismatch {
354
+ store. validate_identifier_call ( Err ( ChainIdentifierValidationError :: NetVersionMismatch {
355
355
chain_name : "chain-1" . into ( ) ,
356
356
store_net_version : "0" . to_owned ( ) ,
357
357
chain_net_version : "1" . to_owned ( ) ,
@@ -382,7 +382,7 @@ mod tests {
382
382
#[ tokio:: test]
383
383
async fn check_fails_on_identifier_network_version_mismatch ( ) {
384
384
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
385
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: NetVersionMismatch {
385
+ store. validate_identifier_call ( Err ( ChainIdentifierValidationError :: NetVersionMismatch {
386
386
chain_name : "chain-1" . into ( ) ,
387
387
store_net_version : "2" . to_owned ( ) ,
388
388
chain_net_version : "1" . to_owned ( ) ,
@@ -413,11 +413,13 @@ mod tests {
413
413
#[ tokio:: test]
414
414
async fn check_fails_on_identifier_genesis_hash_mismatch ( ) {
415
415
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
416
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: GenesisBlockHashMismatch {
417
- chain_name : "chain-1" . into ( ) ,
418
- store_genesis_block_hash : vec ! [ 2 ] . into ( ) ,
419
- chain_genesis_block_hash : vec ! [ 1 ] . into ( ) ,
420
- } ) ) ;
416
+ store. validate_identifier_call ( Err (
417
+ ChainIdentifierValidationError :: GenesisBlockHashMismatch {
418
+ chain_name : "chain-1" . into ( ) ,
419
+ store_genesis_block_hash : vec ! [ 2 ] . into ( ) ,
420
+ chain_genesis_block_hash : vec ! [ 1 ] . into ( ) ,
421
+ } ,
422
+ ) ) ;
421
423
422
424
let check = GenesisHashCheck :: new ( store) ;
423
425
@@ -444,7 +446,8 @@ mod tests {
444
446
#[ tokio:: test]
445
447
async fn check_temporary_failure_on_store_errors ( ) {
446
448
let store = Arc :: new ( TestChainIdentifierStore :: default ( ) ) ;
447
- store. validate_identifier_call ( Err ( ChainIdentifierStoreError :: Store ( anyhow ! ( "error" ) ) ) ) ;
449
+ store
450
+ . validate_identifier_call ( Err ( ChainIdentifierValidationError :: Store ( anyhow ! ( "error" ) ) ) ) ;
448
451
449
452
let check = GenesisHashCheck :: new ( store) ;
450
453
0 commit comments