stacks-blockchain-api icon indicating copy to clipboard operation
stacks-blockchain-api copied to clipboard

feat: exit immediately when stacks-node block desync detected

Open zone117x opened this issue 3 years ago • 2 comments

(Note: for now, this is primarily a testing PR for debugging desync issues)

This PR changes the behavior for when the API encounters a "desync" error with the stacks-node (event emitter). A desync being: when the stacks-node emits a /new_block event containing a pointer to a parent block that the API has not received from any previous /new_block events. Typically this happens when some out-of-order or buggy shutdown sequence occurs between the API and stacks-node.

The API is unable to handle re-orgs and serve data in a "lossy" mode with missing blocks/txs. So prior to this PR, the API would return an http error response to the stacks-node, then the stacks-node would try to re-emit the same event, and this would just repeat indefinitely. This results in the db event_observer_requests table growing indefinitely, and a configured tsv output file growing indefinitely.

With this PR, when a desync occurs, the program exits immediately with a specific error message and exit code.

zone117x avatar Jan 12 '22 18:01 zone117x

🚀 Deployed on https://deploy-preview-973--stacks-blockchain-api.netlify.app

github-actions[bot] avatar Jan 12 '22 18:01 github-actions[bot]

Codecov Report

Merging #973 (ee92ee4) into master (64a4401) will increase coverage by 0.04%. The diff coverage is 53.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #973      +/-   ##
==========================================
+ Coverage   66.88%   66.93%   +0.04%     
==========================================
  Files          95       95              
  Lines       10036    10047      +11     
  Branches     1573     1624      +51     
==========================================
+ Hits         6713     6725      +12     
+ Misses       3319     3318       -1     
  Partials        4        4              
Impacted Files Coverage Δ
src/datastore/postgres-store.ts 84.82% <33.33%> (-0.04%) :arrow_down:
src/shutdown-handler.ts 18.96% <60.00%> (+18.96%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 887b7d6...ee92ee4. Read the comment docs.

codecov-commenter avatar Jan 12 '22 18:01 codecov-commenter

@zone117x This seems abandoned -- any reason not to close?

smcclellan avatar Mar 24 '23 22:03 smcclellan