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

fix: inconsistent block transaction results in Rosetta response #1958

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

zone117x
Copy link
Member

Fix possible cause of Rosetta block lookups returning inconsistent results. E.g. reports of block response with 0 transactions:

curl --location 'https://xxx/block' \
--header 'Content-Type: application/json' \
--data '{
    "network_identifier": {
        "blockchain": "stacks",
        "network": "mainnet"
    },
    "block_identifier": {
        "index": 147250
    }
}'

{
    "block": {
        "block_identifier": {
            "index": 147250,
            "hash": "0x2dc8a524911e12f3c4d14de79ca5893b70c7c34d07d0bef59d31b8568650c07f"
        },
        "parent_block_identifier": {
            "index": 147249,
            "hash": "0x52ae92098398349b936e1b1c29591150566d38b800101dc0dff805c47aca2f0b"
        },
        "timestamp": 1713772872000,
        "transactions": []
    }
}

Comment on lines 469 to 478
return await db.sqlTransaction(async sql => {
let query;
let blockQuery: FoundOrNot<DbBlock>;
if (blockHash) {
query = db.getBlock({ hash: blockHash });
blockQuery = await db.getBlock({ hash: blockHash });
} else if (blockHeight && blockHeight > 0) {
query = db.getBlock({ height: blockHeight });
blockQuery = await db.getBlock({ height: blockHeight });
} else {
query = db.getCurrentBlock();
blockQuery = await db.getCurrentBlock();
}
const blockQuery = await query;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These synchronous calls to db.get... before performing an await likely broke the implicit sql transaction handling where we leverage AsyncLocalStorage. IIUC, synchronous invocations of functions that return a promise break the async context.

@zone117x zone117x requested a review from rafaelcr April 23, 2024 17:17
Copy link

Vercel deployment URL: https://stacks-blockchain-fm7uez7ec-blockstack.vercel.app 🚀

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 36.14%. Comparing base (20097fc) to head (21c54a7).
Report is 230 commits behind head on develop.

Files Patch % Lines
src/api/controllers/db-controller.ts 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1958       +/-   ##
============================================
- Coverage    76.82%   36.14%   -40.68%     
============================================
  Files           80       94       +14     
  Lines        11515    12555     +1040     
  Branches      2575     2926      +351     
============================================
- Hits          8846     4538     -4308     
- Misses        2540     7470     +4930     
- Partials       129      547      +418     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zone117x zone117x merged commit a5bec61 into develop Apr 23, 2024
30 of 31 checks passed
@zone117x zone117x deleted the fix/rosetta-sql-transactional-consistency branch April 23, 2024 17:26
blockstack-devops pushed a commit that referenced this pull request Apr 23, 2024
## [7.11.0-beta.4](v7.11.0-beta.3...v7.11.0-beta.4) (2024-04-23)

### Bug Fixes

* inconsistent block transaction results in Rosetta response ([#1958](#1958)) ([a5bec61](a5bec61))
@blockstack-devops
Copy link

🎉 This PR is included in version 7.11.0-beta.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Jun 7, 2024
## [7.11.0](v7.10.0...v7.11.0) (2024-06-07)

### Features

* add average stacks block time to burn block endpoints ([#1963](#1963)) ([31c2eed](31c2eed))
* add burn_block_height to Rosetta endpoints ([#1974](#1974)) ([9648ac8](9648ac8))
* add burn_block_height to transactions ([#1969](#1969)) ([3e2d524](3e2d524))
* add signer_address to pox signer endpoints ([#1975](#1975)) ([7d3444b](7d3444b))
* add total tx count to burn block endpoints ([#1965](#1965)) ([d38b78a](d38b78a))
* average block times endpoint ([#1962](#1962)) ([cd151aa](cd151aa))
* docker build for arm ([#1947](#1947)) ([2c526fc](2c526fc))
* include solo and pooled stackers in signer stacker endpoints ([#1987](#1987)) ([302a5d8](302a5d8))
* support multiple STX faucet source accounts ([#1946](#1946)) ([be5db0c](be5db0c))
* support multiple STX faucet source accounts ([#1946](#1946)) ([5d69c7c](5d69c7c))

### Bug Fixes

* ensure events are inserted into the raw event request table ([#1925](#1925)) ([34a8454](34a8454))
* inconsistent block transaction results in Rosetta response ([#1958](#1958)) ([a5bec61](a5bec61))
* issue with block_time receipt not being written to db ([#1961](#1961)) ([74c06c6](74c06c6))
* pox4 properties missing in various endpoints ([#1977](#1977)) ([521d771](521d771))
* rosetta account endpoint should assume chain tip if block not specified ([#1956](#1956)) ([4bba526](4bba526))
* signer stacker query using string instead of int for cycle_id ([#1991](#1991)) ([5ce9b44](5ce9b44))
* socket-io client must only use websocket transport ([#1976](#1976)) ([85ea5af](85ea5af))
@blockstack-devops
Copy link

🎉 This PR is included in version 7.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants