From dacab21f283668e71f362b196525c00bb146eb6d Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Tue, 2 Oct 2018 09:56:02 -0500 Subject: [PATCH 1/2] Failing regression test for #838 --- apps/explorer/lib/explorer/chain.ex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index d34ff3c7b3..bbb54cd2d8 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1164,6 +1164,14 @@ defmodule Explorer.Chain do iex> Explorer.Chain.missing_block_number_ranges(5..0) [4..3, 1..1] + If only non-consensus blocks exist for a number, the number still counts as missing. + + iex> insert(:block, number: 0) + iex> insert(:block, number: 1, consensus: false) + iex> insert(:block, number: 2) + iex> Explorer.Chain.missing_block_number_ranges(2..0) + [1..1] + """ @spec missing_block_number_ranges(Range.t()) :: [Range.t()] def missing_block_number_ranges(range) From 1e14446ee93540e6c616ce6e06cf325c692b0ff9 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Tue, 2 Oct 2018 09:58:00 -0500 Subject: [PATCH 2/2] Only count consensus blocks as not missing. Fixes #838 --- apps/explorer/lib/explorer/chain.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index bbb54cd2d8..cb4777363e 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1132,7 +1132,7 @@ defmodule Explorer.Chain do end @doc """ - Calculates the ranges of missing blocks in `range`. + Calculates the ranges of missing consensus blocks in `range`. When there are no blocks, the entire range is missing. @@ -1196,7 +1196,8 @@ defmodule Explorer.Chain do FROM generate_series(? :: bigint, ? :: bigint, ? :: bigint) AS number EXCEPT SELECT blocks.number - FROM blocks) + FROM blocks + WHERE blocks.consensus = true) SELECT no_previous.number AS minimum, (SELECT MIN(no_next.number) FROM missing_blocks AS no_next