blockscout
blockscout copied to clipboard
fix: Transactions and token transfers block_consensus
Motivation
Reorgs detection and marking blocks as consensus: false (along with transactions and token transfers block_consensus: false) is executed in the different import stage from inserting transactions and token transfers. It means that these queries are executed in different DB transactions. It means that there is a space for race condition.
For example:
- Some block is already inserted in DB but its transactions and token transfers aren't
- Process of importing new block with the same number begins
- Consensus of the block imported in step 1 is set to
falsesince now it's a reorg - Consensus of transactions and token transfers of that reorg are set to
false(but they are not inserted yet, so nothing happens) - Transactions and token transfers of the block inserted in step 1 are inserted with
block_consensus: trueeven though this block is already lost its consensus.
As a result we have inconsistency of block consensus field and transaction/token transfer block_consensus fields.
Changelog
- Move
TransactionsandTokenTransfersrunners to the same import stage (same DB transaction) withBlocksrunner - Add background migrations for correction of
block_consensusfields