Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ARCO-115): Reorg Support #611

Merged
merged 36 commits into from
Dec 5, 2024
Merged

feat(ARCO-115): Reorg Support #611

merged 36 commits into from
Dec 5, 2024

Conversation

kuba-4chain
Copy link
Collaborator

@kuba-4chain kuba-4chain commented Oct 16, 2024

Description of Changes

  1. Processing of blocks received from peers was improved to allow for:
    • proper handling of ORPHANED blocks - updating them backwards with each new incoming block that extends the orphaned chain and publishing their transactions if they become part of the longest chain
    • secure handling of concurrent blocks being processed - by updating the UpsertBlock query with additional checks
  2. Database method GetBlockGaps was updated and simplified.
  3. The sum of chainworks of competing forks is now compared to find out the longest chain, instead of comparing the chainwork of only the tips of forks.
  4. A great number of fixtures and unit tests were added to ensure maximum test coverage - as this is a rare scenario, difficult to spot and debug in production.
  5. E2E tests were improved, by decreasing the fillGapsInterval to 1 second - to make sure there are no gaps when the tests begin.
  6. A new transaction status MINED_IN_STALE_BLOCK was introduced in metamorph api.
  7. The way of publishing mined transactions to metamorph was updated
    • transactions from incoming block, that's extending the longest chain, are published to metamorph as MINED - no change here
    • transactions from incoming block, that's extending a stale chain, that are not found in the longest chain are in SEEN_ON_NETWORK state (ignored) until they are found in the longest chain (which eventually should happen, because nodes put those transactions back in their mempool)
    • in case of reorg, transactions from the entire stale chain, that is now becoming the longest chain, are published
      • transactions that were previously found in the longest chain that is now becoming a stale chain are published with updated block data (block hash, block height and merkle path)
      • transactions that were not found in the longest chain are published as newly mined
    • in case of reorg, transactions from the previously longest chain that were NOT found in the new longest chain are published as MINED_IN_STALE_BLOCK - this is to inform users that their transaction is no longer mined in the longest chain, so they have to wait until it's MINED again
  8. An integration test for the entire reorg process, including updating transactions, was written, covering all of the above-mentioned scenarios and some more edge cases - for single-instance processing.
  9. Small refactor of structures
    • PeerTxMessage -> TxStatusMessage
    • GetMinedTransactionsResult -> TransactionBlock
    • New structure chain -> slice of blocks

Flow diagram of the updated processBlock function in blocktx processor

ReorgSupport drawio

Linked Issues / Tickets

ARCO-178
ARCO-179
ARCO-199

Testing Procedure

Describe the tests you've added or any testing steps you've taken.

  • I have added new unit tests
  • All tests pass locally
  • I have tested manually in my local environment

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have updated CHANGELOG.md with my changes

@boecklim boecklim assigned boecklim and kuba-4chain and unassigned boecklim Oct 23, 2024
@kuba-4chain kuba-4chain changed the title Reorg Support feat(ARCO-115): Reorg Support Nov 8, 2024
@kuba-4chain kuba-4chain force-pushed the reorg-support branch 2 times, most recently from 4d49ace to ea33f58 Compare November 22, 2024 12:46
@kuba-4chain kuba-4chain force-pushed the reorg-support branch 2 times, most recently from 0dcabf9 to 2868570 Compare November 28, 2024 10:47
@kuba-4chain kuba-4chain force-pushed the reorg-support branch 2 times, most recently from 413bd3e to 680e8d5 Compare December 4, 2024 17:15
@boecklim boecklim mentioned this pull request Dec 5, 2024
7 tasks
Copy link

sonarqubecloud bot commented Dec 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
79.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@kuba-4chain kuba-4chain merged commit 023dd8c into main Dec 5, 2024
7 of 8 checks passed
@kuba-4chain kuba-4chain deleted the reorg-support branch December 5, 2024 14:10
github-actions bot pushed a commit that referenced this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants