Skip to content

Commit 1a47b7c

Browse files
node: Validate copy offset against earliest block number (#6384)
1 parent 281f2e2 commit 1a47b7c

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

node/src/manager/commands/copy.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,31 @@ async fn create_inner(
114114
.await?;
115115
let network = query_store.network_name();
116116

117-
let src_ptr = query_store.block_ptr().await?.ok_or_else(|| anyhow!("subgraph {} has not indexed any blocks yet and can not be used as the source of a copy", src))?;
118-
let src_number = if src_ptr.number <= block_offset {
119-
bail!("subgraph {} has only indexed up to block {}, but we need at least block {} before we can copy from it", src, src_ptr.number, block_offset);
120-
} else {
121-
src_ptr.number - block_offset
122-
};
117+
let src_ptr = query_store
118+
.block_ptr()
119+
.await?
120+
.ok_or_else(|| anyhow!("subgraph {} has not indexed any blocks yet and can not be used as the source of a copy", src))?;
121+
122+
if src_ptr.number <= block_offset {
123+
bail!("subgraph {} has only indexed up to block {}, but we need at least block {} before we can copy from it",
124+
src,
125+
src_ptr.number,
126+
block_offset
127+
);
128+
}
129+
130+
// Validate that the offset block does not fall behind the subgraph's earliest block.
131+
let src_state = query_store.deployment_state().await?;
132+
let src_number = src_ptr.number - block_offset;
133+
if src_number < src_state.earliest_block_number {
134+
bail!(
135+
"cannot copy subgraph {} with --offset {}: the offset block number {} is behind the subgraph's earliest_block_number {}",
136+
src,
137+
block_offset,
138+
src_number,
139+
src_state.earliest_block_number,
140+
);
141+
}
123142

124143
let chain_store = store
125144
.block_store()

0 commit comments

Comments
 (0)