Skip to content

Commit 8297527

Browse files
committed
expose blockchain kind
1 parent ef34e98 commit 8297527

File tree

5 files changed

+59
-22
lines changed

5 files changed

+59
-22
lines changed

chain/ethereum/src/ethereum_adapter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use futures::future;
22
use futures::prelude::*;
33
use futures03::{future::BoxFuture, stream::FuturesUnordered};
44
use graph::blockchain::BlockHash;
5+
use graph::blockchain::BlockchainKind;
56
use graph::blockchain::ChainIdentifier;
67
use graph::components::transaction_receipt::LightTransactionReceipt;
78
use graph::data::subgraph::UnifiedMappingApiVersion;

graph/src/blockchain/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use crate::prelude::{r, BigInt, TryFromValue, ValueMap};
99
use crate::util::stable_hash_glue::{impl_stable_hash, AsBytes};
1010
use crate::{cheap_clone::CheapClone, components::store::BlockNumber};
1111

12+
use super::BlockchainKind;
13+
1214
/// A simple marker for byte arrays that are really block hashes
1315
#[derive(Clone, Default, PartialEq, Eq, Hash)]
1416
pub struct BlockHash(pub Box<[u8]>);

node/src/store_builder.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::iter::FromIterator;
22
use std::{collections::HashMap, sync::Arc};
33

44
use futures::future::join_all;
5-
use graph::blockchain::ChainIdentifier;
5+
use graph::blockchain::{BlockchainKind, ChainIdentifier};
66
use graph::prelude::{o, MetricsRegistry, NodeId};
77
use graph::url::Url;
88
use graph::{
@@ -25,7 +25,7 @@ pub struct StoreBuilder {
2525
subscription_manager: Arc<SubscriptionManager>,
2626
chain_head_update_listener: Arc<PostgresChainHeadUpdateListener>,
2727
/// Map network names to the shards where they are/should be stored
28-
chains: HashMap<String, ShardName>,
28+
chains: HashMap<String, ShardName, BlockchainKind>,
2929
}
3030

3131
impl StoreBuilder {
@@ -61,11 +61,12 @@ impl StoreBuilder {
6161
// using the pool
6262
join_all(pools.iter().map(|(_, pool)| pool.setup())).await;
6363

64-
let chains = HashMap::from_iter(config.chains.chains.iter().map(|(name, chain)| {
65-
let shard = ShardName::new(chain.shard.to_string())
66-
.expect("config validation catches invalid names");
67-
(name.to_string(), shard)
68-
}));
64+
let chains: HashMap<String, ShardName, BlockchainKind> =
65+
HashMap::from_iter(config.chains.chains.iter().map(|(name, chain)| {
66+
let shard = ShardName::new(chain.shard.to_string())
67+
.expect("config validation catches invalid names");
68+
(name.to_string(), shard, chain.protocol)
69+
}));
6970

7071
let chain_head_update_listener = Arc::new(PostgresChainHeadUpdateListener::new(
7172
&logger,
@@ -154,13 +155,17 @@ impl StoreBuilder {
154155
logger: &Logger,
155156
pools: HashMap<ShardName, ConnectionPool>,
156157
subgraph_store: Arc<SubgraphStore>,
157-
chains: HashMap<String, ShardName>,
158+
chains: HashMap<String, (Option<ShardName>, BlockchainKind)>,
158159
networks: Vec<(String, Vec<ChainIdentifier>)>,
159160
) -> Arc<DieselStore> {
160161
let networks = networks
161162
.into_iter()
162163
.map(|(name, idents)| {
163-
let shard = chains.get(&name).unwrap_or(&*PRIMARY_SHARD).clone();
164+
let shard = chains
165+
.get(&name)
166+
.map(|v| v.0)
167+
.unwrap_or(&*PRIMARY_SHARD)
168+
.clone();
164169
(name, idents, shard)
165170
})
166171
.collect();

store/postgres/src/block_store.rs

+38-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
};
77

88
use graph::{
9-
blockchain::ChainIdentifier,
9+
blockchain::{BlockchainKind, ChainIdentifier},
1010
components::store::BlockStore as BlockStoreTrait,
1111
prelude::{error, warn, BlockNumber, BlockPtr, Logger},
1212
};
@@ -200,7 +200,7 @@ impl BlockStore {
200200
pub fn new(
201201
logger: Logger,
202202
// (network, ident, shard)
203-
chains: Vec<(String, Vec<ChainIdentifier>, Shard)>,
203+
chains: Vec<(String, Vec<(ChainIdentifier, BlockchainKind)>, Shard)>,
204204
// shard -> pool
205205
pools: HashMap<Shard, ConnectionPool>,
206206
sender: Arc<NotificationSender>,
@@ -222,11 +222,28 @@ impl BlockStore {
222222
chain_head_cache,
223223
};
224224

225+
let chains: Vec<(String, Vec<ChainIdentifierExt>, Shard)> = chains
226+
.into_iter()
227+
.map(|(name, idents, shard)| {
228+
let idents = idents
229+
.into_iter()
230+
.map(|(ident, kind)| ChainIdentifierExt { ident, kind })
231+
.collect();
232+
(name, idents, shard)
233+
})
234+
.collect();
235+
236+
#[derive(Debug, Eq, PartialEq, Hash, Clone)]
237+
struct ChainIdentifierExt {
238+
ident: ChainIdentifier,
239+
kind: BlockchainKind,
240+
}
241+
225242
fn reduce_idents(
226243
chain_name: &str,
227-
idents: Vec<ChainIdentifier>,
228-
) -> Result<Option<ChainIdentifier>, StoreError> {
229-
let mut idents: HashSet<ChainIdentifier> = HashSet::from_iter(idents.into_iter());
244+
idents: Vec<ChainIdentifierExt>,
245+
) -> Result<Option<ChainIdentifierExt>, StoreError> {
246+
let mut idents: HashSet<ChainIdentifierExt> = HashSet::from_iter(idents.into_iter());
230247
match idents.len() {
231248
0 => Ok(None),
232249
1 => Ok(idents.drain().next()),
@@ -245,7 +262,7 @@ impl BlockStore {
245262
logger: &Logger,
246263
chain: &primary::Chain,
247264
shard: &Shard,
248-
ident: &Option<ChainIdentifier>,
265+
ident: &Option<ChainIdentifierExt>,
249266
) -> bool {
250267
if &chain.shard != shard {
251268
error!(
@@ -258,7 +275,7 @@ impl BlockStore {
258275
return false;
259276
}
260277
match ident {
261-
Some(ident) => {
278+
Some(ChainIdentifierExt { ident, kind: _ }) => {
262279
if chain.net_version != ident.net_version {
263280
error!(logger,
264281
"the net version for chain {} has changed from {} to {} since the last time we ran",
@@ -301,16 +318,21 @@ impl BlockStore {
301318
} else {
302319
ChainStatus::ReadOnly
303320
};
304-
block_store.add_chain_store(chain, status, false)?;
321+
block_store.add_chain_store(chain, status, ident.map(|id| id.kind), false)?;
305322
}
306323
(None, Some(ident)) => {
307324
let chain = primary::add_chain(
308325
block_store.mirror.primary(),
309326
&chain_name,
310-
&ident,
327+
&ident.ident,
311328
&shard,
312329
)?;
313-
block_store.add_chain_store(&chain, ChainStatus::Ingestible, true)?;
330+
block_store.add_chain_store(
331+
&chain,
332+
ChainStatus::Ingestible,
333+
Some(ident.kind),
334+
true,
335+
)?;
314336
}
315337
(None, None) => {
316338
error!(
@@ -335,7 +357,9 @@ impl BlockStore {
335357
.iter()
336358
.filter(|chain| !configured_chains.contains(&chain.name))
337359
{
338-
block_store.add_chain_store(chain, ChainStatus::ReadOnly, false)?;
360+
// Here we pass None to blockchain kind because we don't have a way of knowing whether this chain was an EVM chain.
361+
// This should only affect the determinism of the meta block in
362+
block_store.add_chain_store(chain, ChainStatus::ReadOnly, None, false)?;
339363
}
340364
Ok(block_store)
341365
}
@@ -352,6 +376,7 @@ impl BlockStore {
352376
&self,
353377
chain: &primary::Chain,
354378
status: ChainStatus,
379+
kind: Option<BlockchainKind>,
355380
create: bool,
356381
) -> Result<Arc<ChainStore>, StoreError> {
357382
let pool = self
@@ -372,6 +397,7 @@ impl BlockStore {
372397
status,
373398
sender,
374399
pool,
400+
kind,
375401
);
376402
if create {
377403
store.create(&ident)?;
@@ -425,7 +451,7 @@ impl BlockStore {
425451
self.mirror.read(|conn| {
426452
primary::find_chain(conn, chain).and_then(|chain| {
427453
chain
428-
.map(|chain| self.add_chain_store(&chain, ChainStatus::ReadOnly, false))
454+
.map(|chain| self.add_chain_store(&chain, ChainStatus::ReadOnly, None, false))
429455
.transpose()
430456
})
431457
})

store/postgres/src/chain_store.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
time::Duration,
1313
};
1414

15-
use graph::blockchain::{Block, BlockHash, ChainIdentifier};
15+
use graph::blockchain::{Block, BlockHash, BlockchainKind, ChainIdentifier};
1616
use graph::cheap_clone::CheapClone;
1717
use graph::prelude::web3::types::H256;
1818
use graph::prelude::{
@@ -1268,6 +1268,7 @@ pub struct ChainStore {
12681268
status: ChainStatus,
12691269
chain_head_update_sender: ChainHeadUpdateSender,
12701270
block_cache: TimedCache<&'static str, BlockPtr>,
1271+
blockchain_kind: Option<BlockchainKind>,
12711272
}
12721273

12731274
impl ChainStore {
@@ -1278,6 +1279,7 @@ impl ChainStore {
12781279
status: ChainStatus,
12791280
chain_head_update_sender: ChainHeadUpdateSender,
12801281
pool: ConnectionPool,
1282+
blockchain_kind: Option<BlockchainKind>,
12811283
) -> Self {
12821284
ChainStore {
12831285
pool,
@@ -1287,6 +1289,7 @@ impl ChainStore {
12871289
status,
12881290
chain_head_update_sender,
12891291
block_cache: TimedCache::new(Duration::from_secs(5)),
1292+
blockchain_kind,
12901293
}
12911294
}
12921295

0 commit comments

Comments
 (0)