-- Which block each indexed row was decoded from (blackbeard/observer#52). -- -- `chain_event` and `chain_extrinsic` are keyed on `(chain, height, index)` -- and said nothing about *which* block at that height they came from. A reorg -- replaces the block at a height, and an upsert by index cannot remove rows the -- replacement does not have: mainnet 61041 kept the losing fork's -- `MinerRewarded`, `Minted` and `NativeTransferred` to baba-gorchitsa beside -- the winner's exit, so that account was credited 0.31 QTC the chain never paid -- it and QUANPOOL's reward at that height was never indexed at all. -- -- With the hash on every row, indexing a height first removes whatever was read -- from a different block, then writes. Rows from before this migration carry -- null, which is "provenance unknown" and is treated as different from -- everything. alter table chain_event add column block_hash text; alter table chain_extrinsic add column block_hash text; -- Re-read every block, so that every row gains a hash and every height that a -- reorg left mixed is replaced by its canonical block's events. The backfill -- also compares the `block` row at each height it walks against the canonical -- hash, so the same pass corrects block rows a reorg left behind. Collapsing to -- the top as 0008 did: the backfill walks down to genesis again, and -- `indexed_from` reports the real, shrinking range while it does. update event_scan set low = high, updated_at = now();