Skip to content

Commit b8f5d82

Browse files
committed
chain, graph, store: Add automocks for store traits
This required `ChainStore::upsert_blocks` to use a `'static` lifetime for its input stream and output error types. The only place where `upsert_blocks` is used is in `BlockIngestor`, which can safely use `'static`, as operates on a static reference of itself.
1 parent 4eb1723 commit b8f5d82

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

chain/ethereum/src/block_ingestor.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ where
146146
})
147147
}
148148

149-
fn do_poll<'a>(&'a self) -> impl Future<Item = (), Error = EthereumAdapterError> + 'a {
149+
fn do_poll(&'static self) -> impl Future<Item = (), Error = EthereumAdapterError> + 'static {
150150
trace!(self.logger, "BlockIngestor::do_poll");
151151
let network_name = self.network_name.clone();
152152
// Get chain head ptr from store
@@ -248,12 +248,11 @@ where
248248
/// head block pointer. If missing blocks prevent such an update, return a Vec with at least
249249
/// one of the missing blocks' hashes.
250250
fn ingest_blocks<
251-
'a,
252-
B: Stream<Item = EthereumBlock, Error = EthereumAdapterError> + Send + 'a,
251+
B: Stream<Item = EthereumBlock, Error = EthereumAdapterError> + Send + 'static,
253252
>(
254-
&'a self,
253+
&'static self,
255254
blocks: B,
256-
) -> impl Future<Item = Vec<H256>, Error = EthereumAdapterError> + Send + 'a {
255+
) -> impl Future<Item = Vec<H256>, Error = EthereumAdapterError> + Send + 'static {
257256
self.chain_store.upsert_blocks(blocks).and_then(move |()| {
258257
self.chain_store
259258
.attempt_chain_head_update(self.ancestor_count)
@@ -266,10 +265,10 @@ where
266265

267266
/// Requests the specified blocks via web3, returning them in a stream (potentially out of
268267
/// order).
269-
fn get_blocks<'a>(
270-
&'a self,
268+
fn get_blocks(
269+
&'static self,
271270
block_hashes: &[H256],
272-
) -> Box<dyn Stream<Item = EthereumBlock, Error = EthereumAdapterError> + Send + 'a> {
271+
) -> Box<dyn Stream<Item = EthereumBlock, Error = EthereumAdapterError> + Send + 'static> {
273272
let logger = self.logger.clone();
274273
let eth_adapter = self.eth_adapter.clone();
275274

graph/src/components/store.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,7 @@ pub trait Store: Send + Sync + 'static {
11721172
) -> Result<Option<BlockNumber>, StoreError>;
11731173
}
11741174

1175+
#[automock]
11751176
pub trait SubgraphDeploymentStore: Send + Sync + 'static {
11761177
/// Return the GraphQL schema supplied by the user
11771178
fn input_schema(&self, subgraph_id: &SubgraphDeploymentId) -> Result<Arc<Schema>, Error>;
@@ -1188,15 +1189,19 @@ pub trait SubgraphDeploymentStore: Send + Sync + 'static {
11881189
}
11891190

11901191
/// Common trait for blockchain store implementations.
1192+
#[automock]
11911193
pub trait ChainStore: Send + Sync + 'static {
11921194
/// Get a pointer to this blockchain's genesis block.
11931195
fn genesis_block_ptr(&self) -> Result<EthereumBlockPointer, Error>;
11941196

11951197
/// Insert blocks into the store (or update if they are already present).
1196-
fn upsert_blocks<'a, B, E>(&self, _: B) -> Box<dyn Future<Item = (), Error = E> + Send + 'a>
1198+
fn upsert_blocks<B, E>(
1199+
&self,
1200+
_blocks: B,
1201+
) -> Box<dyn Future<Item = (), Error = E> + Send + 'static>
11971202
where
1198-
B: Stream<Item = EthereumBlock, Error = E> + Send + 'a,
1199-
E: From<Error> + Send + 'a,
1203+
B: Stream<Item = EthereumBlock, Error = E> + Send + 'static,
1204+
E: From<Error> + Send + 'static,
12001205
Self: Sized,
12011206
{
12021207
unimplemented!()

store/postgres/src/store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,13 +1116,13 @@ impl ChainStore for Store {
11161116
Ok(self.genesis_block_ptr)
11171117
}
11181118

1119-
fn upsert_blocks<'a, B, E>(
1119+
fn upsert_blocks<B, E>(
11201120
&self,
11211121
blocks: B,
1122-
) -> Box<dyn Future<Item = (), Error = E> + Send + 'a>
1122+
) -> Box<dyn Future<Item = (), Error = E> + Send + 'static>
11231123
where
1124-
B: Stream<Item = EthereumBlock, Error = E> + Send + 'a,
1125-
E: From<Error> + Send + 'a,
1124+
B: Stream<Item = EthereumBlock, Error = E> + Send + 'static,
1125+
E: From<Error> + Send + 'static,
11261126
{
11271127
use crate::db_schema::ethereum_blocks::dsl::*;
11281128

0 commit comments

Comments
 (0)