Skip to content

Commit 52e1ce2

Browse files
committed
graph, node: Rename ChainIdentifierStore to Validator
1 parent c8767c9 commit 52e1ce2

File tree

6 files changed

+48
-45
lines changed

6 files changed

+48
-45
lines changed

graph/src/components/network_provider/chain_identifier_store.rs renamed to graph/src/components/network_provider/chain_identifier_validator.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::components::store::BlockStore;
88
use crate::components::store::ChainStore;
99

1010
/// Additional requirements for stores that are necessary for provider checks.
11-
pub trait ChainIdentifierStore: Send + Sync + 'static {
11+
pub trait ChainIdentifierValidator: Send + Sync + 'static {
1212
/// Verifies that the chain identifier returned by the network provider
1313
/// matches the previously stored value.
1414
///
@@ -17,19 +17,19 @@ pub trait ChainIdentifierStore: Send + Sync + 'static {
1717
&self,
1818
chain_name: &ChainName,
1919
chain_identifier: &ChainIdentifier,
20-
) -> Result<(), ChainIdentifierStoreError>;
20+
) -> Result<(), ChainIdentifierValidationError>;
2121

2222
/// Saves the provided identifier that will be used as the source of truth
2323
/// for future validations.
2424
fn update_identifier(
2525
&self,
2626
chain_name: &ChainName,
2727
chain_identifier: &ChainIdentifier,
28-
) -> Result<(), ChainIdentifierStoreError>;
28+
) -> Result<(), ChainIdentifierValidationError>;
2929
}
3030

3131
#[derive(Debug, Error)]
32-
pub enum ChainIdentifierStoreError {
32+
pub enum ChainIdentifierValidationError {
3333
#[error("identifier not set for chain '{0}'")]
3434
IdentifierNotSet(ChainName),
3535

@@ -51,7 +51,7 @@ pub enum ChainIdentifierStoreError {
5151
Store(#[source] anyhow::Error),
5252
}
5353

54-
impl<C, B> ChainIdentifierStore for B
54+
impl<C, B> ChainIdentifierValidator for B
5555
where
5656
C: ChainStore,
5757
B: BlockStore<ChainStore = C>,
@@ -60,19 +60,19 @@ where
6060
&self,
6161
chain_name: &ChainName,
6262
chain_identifier: &ChainIdentifier,
63-
) -> Result<(), ChainIdentifierStoreError> {
63+
) -> Result<(), ChainIdentifierValidationError> {
6464
let chain_store = self.chain_store(&chain_name).ok_or_else(|| {
65-
ChainIdentifierStoreError::Store(anyhow!(
65+
ChainIdentifierValidationError::Store(anyhow!(
6666
"unable to get store for chain '{chain_name}'"
6767
))
6868
})?;
6969

7070
let store_identifier = chain_store
7171
.chain_identifier()
72-
.map_err(|err| ChainIdentifierStoreError::Store(err))?;
72+
.map_err(|err| ChainIdentifierValidationError::Store(err))?;
7373

7474
if store_identifier.is_default() {
75-
return Err(ChainIdentifierStoreError::IdentifierNotSet(
75+
return Err(ChainIdentifierValidationError::IdentifierNotSet(
7676
chain_name.clone(),
7777
));
7878
}
@@ -84,7 +84,7 @@ where
8484
// but it's possible that it will be created by Firehose. Firehose always returns "0"
8585
// for `net_version`, so we need to allow switching between the two.
8686
if store_identifier.net_version != "0" && chain_identifier.net_version != "0" {
87-
return Err(ChainIdentifierStoreError::NetVersionMismatch {
87+
return Err(ChainIdentifierValidationError::NetVersionMismatch {
8888
chain_name: chain_name.clone(),
8989
store_net_version: store_identifier.net_version,
9090
chain_net_version: chain_identifier.net_version.clone(),
@@ -93,7 +93,7 @@ where
9393
}
9494

9595
if store_identifier.genesis_block_hash != chain_identifier.genesis_block_hash {
96-
return Err(ChainIdentifierStoreError::GenesisBlockHashMismatch {
96+
return Err(ChainIdentifierValidationError::GenesisBlockHashMismatch {
9797
chain_name: chain_name.clone(),
9898
store_genesis_block_hash: store_identifier.genesis_block_hash,
9999
chain_genesis_block_hash: chain_identifier.genesis_block_hash.clone(),
@@ -107,15 +107,15 @@ where
107107
&self,
108108
chain_name: &ChainName,
109109
chain_identifier: &ChainIdentifier,
110-
) -> Result<(), ChainIdentifierStoreError> {
110+
) -> Result<(), ChainIdentifierValidationError> {
111111
let chain_store = self.chain_store(&chain_name).ok_or_else(|| {
112-
ChainIdentifierStoreError::Store(anyhow!(
112+
ChainIdentifierValidationError::Store(anyhow!(
113113
"unable to get store for chain '{chain_name}'"
114114
))
115115
})?;
116116

117117
chain_store
118118
.set_chain_identifier(chain_identifier)
119-
.map_err(|err| ChainIdentifierStoreError::Store(err))
119+
.map_err(|err| ChainIdentifierValidationError::Store(err))
120120
}
121121
}

graph/src/components/network_provider/genesis_hash_check.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use slog::error;
66
use slog::warn;
77
use slog::Logger;
88

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;
1111
use crate::components::network_provider::ChainName;
1212
use crate::components::network_provider::NetworkDetails;
1313
use crate::components::network_provider::ProviderCheck;
@@ -17,11 +17,11 @@ use crate::components::network_provider::ProviderName;
1717
/// Requires providers to have the same network version and genesis hash as one
1818
/// previously stored in the database.
1919
pub struct GenesisHashCheck {
20-
chain_identifier_store: Arc<dyn ChainIdentifierStore>,
20+
chain_identifier_store: Arc<dyn ChainIdentifierValidator>,
2121
}
2222

2323
impl GenesisHashCheck {
24-
pub fn new(chain_identifier_store: Arc<dyn ChainIdentifierStore>) -> Self {
24+
pub fn new(chain_identifier_store: Arc<dyn ChainIdentifierValidator>) -> Self {
2525
Self {
2626
chain_identifier_store,
2727
}
@@ -62,7 +62,7 @@ impl ProviderCheck for GenesisHashCheck {
6262
.chain_identifier_store
6363
.validate_identifier(chain_name, &chain_identifier);
6464

65-
use ChainIdentifierStoreError::*;
65+
use ChainIdentifierValidationError::*;
6666

6767
match check_result {
6868
Ok(()) => ProviderCheckStatus::Valid,
@@ -154,16 +154,16 @@ mod tests {
154154

155155
#[derive(Default)]
156156
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>>>,
159159
}
160160

161161
impl TestChainIdentifierStore {
162-
fn validate_identifier_call(&self, x: Result<(), ChainIdentifierStoreError>) {
162+
fn validate_identifier_call(&self, x: Result<(), ChainIdentifierValidationError>) {
163163
self.validate_identifier_calls.lock().unwrap().push(x)
164164
}
165165

166-
fn update_identifier_call(&self, x: Result<(), ChainIdentifierStoreError>) {
166+
fn update_identifier_call(&self, x: Result<(), ChainIdentifierValidationError>) {
167167
self.update_identifier_calls.lock().unwrap().push(x)
168168
}
169169
}
@@ -181,20 +181,20 @@ mod tests {
181181
}
182182

183183
#[async_trait]
184-
impl ChainIdentifierStore for TestChainIdentifierStore {
184+
impl ChainIdentifierValidator for TestChainIdentifierStore {
185185
fn validate_identifier(
186186
&self,
187187
_chain_name: &ChainName,
188188
_chain_identifier: &ChainIdentifier,
189-
) -> Result<(), ChainIdentifierStoreError> {
189+
) -> Result<(), ChainIdentifierValidationError> {
190190
self.validate_identifier_calls.lock().unwrap().remove(0)
191191
}
192192

193193
fn update_identifier(
194194
&self,
195195
_chain_name: &ChainName,
196196
_chain_identifier: &ChainIdentifier,
197-
) -> Result<(), ChainIdentifierStoreError> {
197+
) -> Result<(), ChainIdentifierValidationError> {
198198
self.update_identifier_calls.lock().unwrap().remove(0)
199199
}
200200
}
@@ -288,10 +288,10 @@ mod tests {
288288
#[tokio::test]
289289
async fn check_temporary_failure_on_initial_chain_identifier_update_error() {
290290
let store = Arc::new(TestChainIdentifierStore::default());
291-
store.validate_identifier_call(Err(ChainIdentifierStoreError::IdentifierNotSet(
291+
store.validate_identifier_call(Err(ChainIdentifierValidationError::IdentifierNotSet(
292292
"chain-1".into(),
293293
)));
294-
store.update_identifier_call(Err(ChainIdentifierStoreError::Store(anyhow!("error"))));
294+
store.update_identifier_call(Err(ChainIdentifierValidationError::Store(anyhow!("error"))));
295295

296296
let check = GenesisHashCheck::new(store);
297297

@@ -321,7 +321,7 @@ mod tests {
321321
#[tokio::test]
322322
async fn check_valid_on_initial_chain_identifier_update() {
323323
let store = Arc::new(TestChainIdentifierStore::default());
324-
store.validate_identifier_call(Err(ChainIdentifierStoreError::IdentifierNotSet(
324+
store.validate_identifier_call(Err(ChainIdentifierValidationError::IdentifierNotSet(
325325
"chain-1".into(),
326326
)));
327327
store.update_identifier_call(Ok(()));
@@ -351,7 +351,7 @@ mod tests {
351351
#[tokio::test]
352352
async fn check_valid_when_stored_identifier_network_version_is_zero() {
353353
let store = Arc::new(TestChainIdentifierStore::default());
354-
store.validate_identifier_call(Err(ChainIdentifierStoreError::NetVersionMismatch {
354+
store.validate_identifier_call(Err(ChainIdentifierValidationError::NetVersionMismatch {
355355
chain_name: "chain-1".into(),
356356
store_net_version: "0".to_owned(),
357357
chain_net_version: "1".to_owned(),
@@ -382,7 +382,7 @@ mod tests {
382382
#[tokio::test]
383383
async fn check_fails_on_identifier_network_version_mismatch() {
384384
let store = Arc::new(TestChainIdentifierStore::default());
385-
store.validate_identifier_call(Err(ChainIdentifierStoreError::NetVersionMismatch {
385+
store.validate_identifier_call(Err(ChainIdentifierValidationError::NetVersionMismatch {
386386
chain_name: "chain-1".into(),
387387
store_net_version: "2".to_owned(),
388388
chain_net_version: "1".to_owned(),
@@ -413,11 +413,13 @@ mod tests {
413413
#[tokio::test]
414414
async fn check_fails_on_identifier_genesis_hash_mismatch() {
415415
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+
));
421423

422424
let check = GenesisHashCheck::new(store);
423425

@@ -444,7 +446,8 @@ mod tests {
444446
#[tokio::test]
445447
async fn check_temporary_failure_on_store_errors() {
446448
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"))));
448451

449452
let check = GenesisHashCheck::new(store);
450453

graph/src/components/network_provider/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
mod chain_identifier_store;
1+
mod chain_identifier_validator;
22
mod extended_blocks_check;
33
mod genesis_hash_check;
44
mod network_details;
55
mod provider_check;
66
mod provider_manager;
77

8-
pub use self::chain_identifier_store::ChainIdentifierStore;
9-
pub use self::chain_identifier_store::ChainIdentifierStoreError;
8+
pub use self::chain_identifier_validator::ChainIdentifierValidationError;
9+
pub use self::chain_identifier_validator::ChainIdentifierValidator;
1010
pub use self::extended_blocks_check::ExtendedBlocksCheck;
1111
pub use self::genesis_hash_check::GenesisHashCheck;
1212
pub use self::network_details::NetworkDetails;

node/src/manager/commands/chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graph::blockchain::BlockHash;
77
use graph::blockchain::BlockPtr;
88
use graph::blockchain::ChainIdentifier;
99
use graph::cheap_clone::CheapClone;
10-
use graph::components::network_provider::ChainIdentifierStore;
10+
use graph::components::network_provider::ChainIdentifierValidator;
1111
use graph::components::network_provider::ChainName;
1212
use graph::components::store::StoreError;
1313
use graph::prelude::BlockNumber;

node/src/manager/commands/provider_checks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22
use std::time::Duration;
33

4-
use graph::components::network_provider::ChainIdentifierStore;
4+
use graph::components::network_provider::ChainIdentifierValidator;
55
use graph::components::network_provider::ChainName;
66
use graph::components::network_provider::ExtendedBlocksCheck;
77
use graph::components::network_provider::GenesisHashCheck;
@@ -107,7 +107,7 @@ async fn run_checks(
107107
logger: &Logger,
108108
chain_name: &ChainName,
109109
adapter: &dyn NetworkDetails,
110-
store: Arc<dyn ChainIdentifierStore>,
110+
store: Arc<dyn ChainIdentifierValidator>,
111111
) -> Vec<String> {
112112
let provider_name = adapter.provider_name();
113113

node/src/manager/commands/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::MetricsContext;
1010
use graph::anyhow::bail;
1111
use graph::cheap_clone::CheapClone;
1212
use graph::components::link_resolver::{ArweaveClient, FileSizeLimit};
13-
use graph::components::network_provider::ChainIdentifierStore;
13+
use graph::components::network_provider::ChainIdentifierValidator;
1414
use graph::components::store::DeploymentLocator;
1515
use graph::components::subgraph::Settings;
1616
use graph::endpoint::EndpointMetrics;
@@ -98,7 +98,7 @@ pub async fn run(
9898
Vec::new();
9999

100100
if env_vars.genesis_validation_enabled {
101-
let store: Arc<dyn ChainIdentifierStore> = network_store.block_store();
101+
let store: Arc<dyn ChainIdentifierValidator> = network_store.block_store();
102102

103103
provider_checks.push(Arc::new(
104104
graph::components::network_provider::GenesisHashCheck::new(store),

0 commit comments

Comments
 (0)