Address review comments

pull/1657/head
goodsoft 6 years ago
parent fe25bf7b44
commit f5268fc450
No known key found for this signature in database
GPG Key ID: DF5159A3A5F09D21
  1. 16
      apps/explorer/lib/explorer/chain/import/runner/blocks.ex
  2. 4
      apps/explorer/priv/repo/migrations/scripts/20190326202921_lose_consensus_for_invalid_blocks.sql

@ -573,12 +573,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
initial = from(t in Transaction, where: false)
Enum.reduce(blocks_changes, initial, fn %{consensus: consensus, hash: hash, number: number}, acc ->
case consensus do
false ->
from(transaction in acc, or_where: transaction.block_hash == ^hash and transaction.block_number == ^number)
true ->
if consensus do
from(transaction in acc, or_where: transaction.block_hash != ^hash and transaction.block_number == ^number)
else
from(transaction in acc, or_where: transaction.block_hash == ^hash and transaction.block_number == ^number)
end
end)
end
@ -587,12 +585,10 @@ defmodule Explorer.Chain.Import.Runner.Blocks do
initial = from(b in Block, where: false)
Enum.reduce(blocks_changes, initial, fn %{consensus: consensus, parent_hash: parent_hash, number: number}, acc ->
case consensus do
false ->
acc
true ->
if consensus do
from(block in acc, or_where: block.number == ^(number - 1) and block.hash != ^parent_hash)
else
acc
end
end)
end

@ -1,5 +1,5 @@
UPDATE blocks SET consensus = FALSE
WHERE number IN (
UPDATE blocks SET consensus = FALSE, updated_at = NOW()
WHERE consensus AND number IN (
SELECT b0.number - 1 FROM "blocks" AS b0
LEFT JOIN "blocks" AS b1 ON (b0."parent_hash" = b1."hash") AND b1."consensus"
WHERE b0."number" > 0 AND b0."consensus" AND b1."hash" IS NULL

Loading…
Cancel
Save