blockscout icon indicating copy to clipboard operation
blockscout copied to clipboard

fix: Transactions and token transfers block_consensus

Open Qwerty5Uiop opened this issue 1 year ago • 0 comments

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:

  1. Some block is already inserted in DB but its transactions and token transfers aren't
  2. Process of importing new block with the same number begins
  3. Consensus of the block imported in step 1 is set to false since now it's a reorg
  4. Consensus of transactions and token transfers of that reorg are set to false (but they are not inserted yet, so nothing happens)
  5. Transactions and token transfers of the block inserted in step 1 are inserted with block_consensus: true even 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 Transactions and TokenTransfers runners to the same import stage (same DB transaction) with Blocks runner
  • Add background migrations for correction of block_consensus fields

Qwerty5Uiop avatar Jun 19 '24 16:06 Qwerty5Uiop