Skip to content

Commit 8eaa3e5

Browse files
committed
substreams: Make a missing timestamp an error
1 parent a5b98d7 commit 8eaa3e5

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

chain/substreams/src/mapper.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use graph::data_source::CausalityRegion;
1414
use graph::prelude::{async_trait, BigInt, BlockHash, BlockNumber, Logger, Value};
1515
use graph::prelude::{BigDecimal, BlockPtr};
1616
use graph::schema::InputSchema;
17+
use graph::slog::error;
1718
use graph::substreams::Clock;
1819
use prost::Message;
1920

@@ -42,7 +43,7 @@ impl BlockStreamMapper<Chain> for WasmBlockMapper {
4243

4344
async fn handle_substreams_block(
4445
&self,
45-
_logger: &Logger,
46+
logger: &Logger,
4647
clock: Clock,
4748
cursor: FirehoseCursor,
4849
block: Vec<u8>,
@@ -60,12 +61,20 @@ impl BlockStreamMapper<Chain> for WasmBlockMapper {
6061

6162
let block_data = block.into_boxed_slice();
6263

63-
// This is not a great idea: we really always need a timestamp; if
64-
// substreams doesn't give us one, we use a fixed one which will
65-
// lead to all kinds of strange behavior
66-
let timestamp = timestamp
67-
.map(|ts| BlockTime::since_epoch(ts.seconds, ts.nanos as u32))
68-
.unwrap_or(BlockTime::NONE);
64+
// `timestamp` is an `Option`, but it should always be set
65+
let timestamp = match timestamp {
66+
None => {
67+
error!(logger,
68+
"Substream block is missing a timestamp";
69+
"cursor" => cursor.to_string(),
70+
"number" => number,
71+
);
72+
return Err(anyhow!(
73+
"Substream block is missing a timestamp at cursor {cursor}, block number {number}"
74+
));
75+
}
76+
Some(ts) => BlockTime::since_epoch(ts.seconds, ts.nanos as u32),
77+
};
6978

7079
Ok(BlockStreamEvent::ProcessWasmBlock(
7180
block_ptr,

0 commit comments

Comments
 (0)