Skip to content

Commit e78dd20

Browse files
node, store: Remove unused ChainStatus enum. Change the shard mismatch log from error to warn
1 parent 281f2e2 commit e78dd20

File tree

4 files changed

+16
-58
lines changed

4 files changed

+16
-58
lines changed

node/src/manager/commands/chain.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use graph_store_postgres::add_chain;
2626
use graph_store_postgres::find_chain;
2727
use graph_store_postgres::update_chain_name;
2828
use graph_store_postgres::BlockStore;
29-
use graph_store_postgres::ChainStatus;
3029
use graph_store_postgres::ChainStore;
3130
use graph_store_postgres::PoolCoordinator;
3231
use graph_store_postgres::ScopedFutureExt;
@@ -254,7 +253,7 @@ pub async fn change_block_cache_shard(
254253

255254
let chain = BlockStore::allocate_chain(conn, &chain_name, &shard, &ident).await?;
256255

257-
store.add_chain_store(&chain,ChainStatus::Ingestible, true).await?;
256+
store.add_chain_store(&chain, true).await?;
258257

259258
// Drop the foreign key constraint on deployment_schemas
260259
sql_query(

store/postgres/src/block_store.rs

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use graph::{
1010
blockchain::ChainIdentifier,
1111
components::store::{BlockStore as BlockStoreTrait, QueryPermit},
1212
derive::CheapClone,
13-
prelude::{error, info, BlockNumber, BlockPtr, Logger, ENV_VARS},
13+
prelude::{error, info, warn, BlockNumber, BlockPtr, Logger, ENV_VARS},
1414
slog::o,
1515
};
1616
use graph::{
@@ -37,14 +37,6 @@ pub const FAKE_NETWORK_SHARED: &str = "fake_network_shared";
3737
// To be incremented on each breaking change to the database.
3838
const SUPPORTED_DB_VERSION: i64 = 3;
3939

40-
/// The status of a chain: whether we can only read from the chain, or
41-
/// whether it is ok to ingest from it, too
42-
#[derive(Copy, Clone)]
43-
pub enum ChainStatus {
44-
ReadOnly,
45-
Ingestible,
46-
}
47-
4840
pub mod primary {
4941
use std::convert::TryFrom;
5042

@@ -278,39 +270,22 @@ impl BlockStore {
278270
});
279271
let block_store = Self { inner };
280272

281-
/// Check that the configuration for `chain` hasn't changed so that
282-
/// it is ok to ingest from it
283-
fn chain_ingestible(
284-
logger: &Logger,
285-
chain: &primary::Chain,
286-
shard: &Shard,
287-
// ident: &ChainIdentifier,
288-
) -> bool {
289-
if &chain.shard != shard {
290-
error!(
291-
logger,
292-
"the chain {} is stored in shard {} but is configured for shard {}",
293-
chain.name,
294-
chain.shard,
295-
shard
296-
);
297-
return false;
298-
}
299-
true
300-
}
301-
302273
// For each configured chain, add a chain store
303274
for (chain_name, shard) in chains {
304275
if let Some(chain) = existing_chains
305276
.iter()
306277
.find(|chain| chain.name == chain_name)
307278
{
308-
let status = if chain_ingestible(&block_store.logger, chain, &shard) {
309-
ChainStatus::Ingestible
310-
} else {
311-
ChainStatus::ReadOnly
312-
};
313-
block_store.add_chain_store(chain, status, false).await?;
279+
if chain.shard != shard {
280+
warn!(
281+
&block_store.logger,
282+
"the chain {} is stored in shard {} but is configured for shard {}",
283+
chain.name,
284+
chain.shard,
285+
shard
286+
);
287+
}
288+
block_store.add_chain_store(chain, false).await?;
314289
};
315290
}
316291

@@ -326,9 +301,7 @@ impl BlockStore {
326301
.iter()
327302
.filter(|chain| !configured_chains.contains(&chain.name))
328303
{
329-
block_store
330-
.add_chain_store(chain, ChainStatus::ReadOnly, false)
331-
.await?;
304+
block_store.add_chain_store(chain, false).await?;
332305
}
333306
Ok(block_store)
334307
}
@@ -376,7 +349,6 @@ impl BlockStore {
376349
pub async fn add_chain_store(
377350
&self,
378351
chain: &primary::Chain,
379-
status: ChainStatus,
380352
create: bool,
381353
) -> Result<Arc<ChainStore>, StoreError> {
382354
let pool = self
@@ -395,7 +367,6 @@ impl BlockStore {
395367
logger,
396368
chain.name.clone(),
397369
chain.storage.clone(),
398-
status,
399370
sender,
400371
pool,
401372
ENV_VARS.store.recent_blocks_cache_capacity,
@@ -457,9 +428,7 @@ impl BlockStore {
457428
async {
458429
match primary::find_chain(conn, &chain).await? {
459430
Some(chain) => {
460-
let chain_store = this
461-
.add_chain_store(&chain, ChainStatus::ReadOnly, false)
462-
.await?;
431+
let chain_store = this.add_chain_store(&chain, false).await?;
463432
Ok(Some(chain_store))
464433
}
465434
None => Ok(None),
@@ -605,7 +574,7 @@ impl BlockStore {
605574
})
606575
.ok_or_else(|| anyhow!("unable to find shard for network {}", network))?;
607576
let chain = primary::add_chain(&mut conn, network, shard, ident).await?;
608-
self.add_chain_store(&chain, ChainStatus::Ingestible, true)
577+
self.add_chain_store(&chain, true)
609578
.await
610579
.map_err(anyhow::Error::from)
611580
}

store/postgres/src/chain_store.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ use graph::{ensure, internal_error};
3737

3838
use self::recent_blocks_cache::RecentBlocksCache;
3939
use crate::AsyncPgConnection;
40-
use crate::{
41-
block_store::ChainStatus, chain_head_listener::ChainHeadUpdateSender, pool::ConnectionPool,
42-
};
40+
use crate::{chain_head_listener::ChainHeadUpdateSender, pool::ConnectionPool};
4341

4442
/// Our own internal notion of a block
4543
#[derive(Clone, Debug)]
@@ -2139,7 +2137,6 @@ pub struct ChainStore {
21392137
pool: ConnectionPool,
21402138
pub chain: String,
21412139
pub(crate) storage: data::Storage,
2142-
status: ChainStatus,
21432140
chain_head_update_sender: ChainHeadUpdateSender,
21442141
// TODO: We currently only use this cache for
21452142
// [`ChainStore::ancestor_block`], but it could very well be expanded to
@@ -2164,7 +2161,6 @@ impl ChainStore {
21642161
logger: Logger,
21652162
chain: String,
21662163
storage: data::Storage,
2167-
status: ChainStatus,
21682164
chain_head_update_sender: ChainHeadUpdateSender,
21692165
pool: ConnectionPool,
21702166
recent_blocks_cache_capacity: usize,
@@ -2182,7 +2178,6 @@ impl ChainStore {
21822178
pool,
21832179
chain,
21842180
storage,
2185-
status,
21862181
chain_head_update_sender,
21872182
recent_blocks_cache,
21882183
blocks_by_hash_cache,
@@ -2193,10 +2188,6 @@ impl ChainStore {
21932188
}
21942189
}
21952190

2196-
pub fn is_ingestible(&self) -> bool {
2197-
matches!(self.status, ChainStatus::Ingestible)
2198-
}
2199-
22002191
/// Execute a cached query, avoiding thundering herd for identical requests.
22012192
/// Returns `(result, was_cached)`.
22022193
async fn cached_lookup<K, T, F>(

store/postgres/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub mod layout_for_tests {
5656

5757
pub use self::block_store::primary::{add_chain, find_chain, update_chain_name};
5858
pub use self::block_store::BlockStore;
59-
pub use self::block_store::ChainStatus;
6059
pub use self::chain_head_listener::ChainHeadUpdateListener;
6160
pub use self::chain_store::{ChainStore, ChainStoreMetrics, Storage};
6261
pub use self::detail::DeploymentDetail;

0 commit comments

Comments
 (0)