Skip to content

Commit cbbb771

Browse files
committed
store: Remove argument from
1 parent 48a9dd8 commit cbbb771

File tree

11 files changed

+42
-91
lines changed

11 files changed

+42
-91
lines changed

chain/ethereum/src/network_indexer/network_indexer.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,7 @@ fn revert_local_head(context: &Context, local_head: EthereumBlockPointer) -> Rev
357357
future::result(
358358
store
359359
.clone()
360-
.revert_block_operations(
361-
subgraph_id.clone(),
362-
local_head.clone(),
363-
parent_block.clone(),
364-
)
360+
.revert_block_operations(subgraph_id.clone(), parent_block.clone())
365361
.map_err(|e| e.into())
366362
.map(|_| (local_head, parent_block)),
367363
)

core/src/subgraph/instance_manager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ where
514514
.store
515515
.revert_block_operations(
516516
ctx.inputs.deployment_id.clone(),
517-
subgraph_ptr,
518517
parent_ptr,
519518
)
520519
.map_err(Into::into)

graph/src/components/ethereum/stream.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use crate::prelude::*;
55

66
pub enum BlockStreamEvent {
77
Block(EthereumBlockWithTriggers),
8-
9-
/// Signals that a revert happened and was processed.
108
Revert(EthereumBlockPointer),
119
}
1210

graph/src/components/store.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,12 @@ pub trait Store: Send + Sync + 'static {
987987
) -> Result<(), StoreError>;
988988

989989
/// Revert the entity changes from a single block atomically in the store, and update the
990-
/// subgraph block pointer from `block_ptr_from` to `block_ptr_to`.
990+
/// subgraph block pointer to `block_ptr_to`.
991991
///
992-
/// `block_ptr_from` must match the current value of the subgraph block pointer.
993-
/// `block_ptr_to` must point to the parent block of `block_ptr_from`.
992+
/// `block_ptr_to` must point to the parent block of the subgraph block pointer.
994993
fn revert_block_operations(
995994
&self,
996995
subgraph_id: SubgraphDeploymentId,
997-
block_ptr_from: EthereumBlockPointer,
998996
block_ptr_to: EthereumBlockPointer,
999997
) -> Result<(), StoreError>;
1000998

@@ -1221,7 +1219,6 @@ impl Store for MockStore {
12211219
fn revert_block_operations(
12221220
&self,
12231221
_subgraph_id: SubgraphDeploymentId,
1224-
_block_ptr_from: EthereumBlockPointer,
12251222
_block_ptr_to: EthereumBlockPointer,
12261223
) -> Result<(), StoreError> {
12271224
unimplemented!()

graphql/tests/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ fn query_detects_reorg() {
15471547

15481548
// Revert one block
15491549
STORE
1550-
.revert_block_operations(id.clone(), BLOCK_ONE.clone(), GENESIS_PTR.clone())
1550+
.revert_block_operations(id.clone(), GENESIS_PTR.clone())
15511551
.unwrap();
15521552
// A query is still fine since we implicitly query at block 0; we were
15531553
// at block 1 when we got `state`, and reorged once by one block, which
@@ -1726,7 +1726,7 @@ fn non_fatal_errors() {
17261726

17271727
// Test error reverts.
17281728
STORE
1729-
.revert_block_operations(id.clone(), BLOCK_TWO.block_ptr(), *BLOCK_ONE)
1729+
.revert_block_operations(id.clone(), *BLOCK_ONE)
17301730
.unwrap();
17311731
let query = "query { musician(id: \"m1\") { id } _meta { hasIndexingErrors } }";
17321732
let query = graphql_parser::parse_query(query).unwrap().into_static();

mock/src/store.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ impl Store for MockStore {
117117
fn revert_block_operations(
118118
&self,
119119
_subgraph_id: SubgraphDeploymentId,
120-
_block_ptr_from: EthereumBlockPointer,
121120
_block_ptr_to: EthereumBlockPointer,
122121
) -> Result<(), StoreError> {
123122
unimplemented!()

store/postgres/src/network_store.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ impl StoreTrait for NetworkStore {
141141
fn revert_block_operations(
142142
&self,
143143
subgraph_id: graph::prelude::SubgraphDeploymentId,
144-
block_ptr_from: EthereumBlockPointer,
145144
block_ptr_to: EthereumBlockPointer,
146145
) -> Result<(), graph::prelude::StoreError> {
147146
self.store
148-
.revert_block_operations(subgraph_id, block_ptr_from, block_ptr_to)
147+
.revert_block_operations(subgraph_id, block_ptr_to)
149148
}
150149

151150
fn subscribe(

store/postgres/src/sharded_store.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,10 @@ impl StoreTrait for ShardedStore {
415415
fn revert_block_operations(
416416
&self,
417417
id: SubgraphDeploymentId,
418-
block_ptr_from: EthereumBlockPointer,
419418
block_ptr_to: EthereumBlockPointer,
420419
) -> Result<(), StoreError> {
421420
let (store, site) = self.store(&id)?;
422-
let event = store.revert_block_operations(site.as_ref(), block_ptr_from, block_ptr_to)?;
421+
let event = store.revert_block_operations(site.as_ref(), block_ptr_to)?;
423422
self.send_store_event(&event)
424423
}
425424

store/postgres/src/store.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,35 +1030,35 @@ impl Store {
10301030
pub(crate) fn revert_block_operations(
10311031
&self,
10321032
site: &Site,
1033-
block_ptr_from: EthereumBlockPointer,
10341033
block_ptr_to: EthereumBlockPointer,
10351034
) -> Result<StoreEvent, StoreError> {
1036-
// Sanity check on block numbers
1037-
if block_ptr_from.number != block_ptr_to.number + 1 {
1038-
panic!("revert_block_operations must revert a single block only");
1039-
}
1040-
// Don't revert past a graft point
10411035
let econn = self.get_entity_conn(site, ReplicaId::Main)?;
1042-
let info = self.subgraph_info_with_conn(&econn.conn, &site.deployment)?;
1043-
if let Some(graft_block) = info.graft_block {
1044-
if graft_block as u64 > block_ptr_to.number {
1045-
return Err(anyhow!(
1046-
"Can not revert subgraph `{}` to block {} as it was \
1047-
grafted at block {} and reverting past a graft point \
1048-
is not possible",
1049-
site.deployment.clone(),
1050-
block_ptr_to.number,
1051-
graft_block
1052-
)
1053-
.into());
1054-
}
1055-
}
10561036

10571037
let event = econn.transaction(|| -> Result<_, StoreError> {
1058-
assert_eq!(
1059-
Some(block_ptr_from),
1060-
Self::block_ptr_with_conn(&site.deployment, &econn)?
1061-
);
1038+
// Unwrap: If we are reverting then the block ptr is not `None`.
1039+
let block_ptr_from = Self::block_ptr_with_conn(&site.deployment, &econn)?.unwrap();
1040+
1041+
// Sanity check on block numbers
1042+
if block_ptr_from.number != block_ptr_to.number + 1 {
1043+
panic!("revert_block_operations must revert a single block only");
1044+
}
1045+
1046+
// Don't revert past a graft point
1047+
let info = self.subgraph_info_with_conn(&econn.conn, &site.deployment)?;
1048+
if let Some(graft_block) = info.graft_block {
1049+
if graft_block as u64 > block_ptr_to.number {
1050+
return Err(anyhow!(
1051+
"Can not revert subgraph `{}` to block {} as it was \
1052+
grafted at block {} and reverting past a graft point \
1053+
is not possible",
1054+
site.deployment.clone(),
1055+
block_ptr_to.number,
1056+
graft_block
1057+
)
1058+
.into());
1059+
}
1060+
}
1061+
10621062
let metadata_event =
10631063
deployment::revert_block_ptr(&econn.conn, &site.deployment, block_ptr_to)?;
10641064

store/postgres/tests/graft.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ fn graft() {
306306
transact_entity_operations(&store, subgraph_id.clone(), BLOCKS[2], vec![op]).unwrap();
307307

308308
store
309-
.revert_block_operations(subgraph_id.clone(), BLOCKS[2], BLOCKS[1])
309+
.revert_block_operations(subgraph_id.clone(), BLOCKS[1])
310310
.expect("We can revert a block we just created");
311311

312312
let err = store
313-
.revert_block_operations(subgraph_id.clone(), BLOCKS[1], BLOCKS[0])
313+
.revert_block_operations(subgraph_id.clone(), BLOCKS[0])
314314
.expect_err("Reverting past graft point is not allowed");
315315

316316
assert!(err.to_string().contains("Can not revert subgraph"));

0 commit comments

Comments
 (0)