From 6c50e2048124aa836bba998f19903f2a6eec6b81 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Thu, 23 Feb 2023 06:53:14 -0800 Subject: [PATCH] chain: Ignore a latest block that would make us go back (#4354) --- chain/ethereum/src/ingestor.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/chain/ethereum/src/ingestor.rs b/chain/ethereum/src/ingestor.rs index 7d902fe5d5f..a0d1f9a8247 100644 --- a/chain/ethereum/src/ingestor.rs +++ b/chain/ethereum/src/ingestor.rs @@ -99,9 +99,22 @@ impl BlockIngestor { // block, as we expect the poll interval to be much shorter than the block time. let latest_block = self.latest_block().await?; - // If latest block matches head block in store, nothing needs to be done - if Some(&latest_block) == head_block_ptr_opt.as_ref() { - return Ok(()); + if let Some(head_block) = head_block_ptr_opt.as_ref() { + // If latest block matches head block in store, nothing needs to be done + if &latest_block == head_block { + return Ok(()); + } + + if latest_block.number < head_block.number { + // An ingestor might wait or move forward, but it never + // wavers and goes back. More seriously, this keeps us from + // later trying to ingest a block with the same number again + warn!(self.logger, + "Provider went backwards - ignoring this latest block"; + "current_block_head" => head_block.number, + "latest_block_head" => latest_block.number); + return Ok(()); + } } // Compare latest block with head ptr, alert user if far behind