Skip to content

Conversation

@zone117x
Copy link
Contributor

@zone117x zone117x commented Dec 12, 2023

Closes #1758

Implement new endpoint returning the list of latest burn blocks:

GET /extended/v1/burn_block

interface Response {
  limit: number;
  offset: number;
  total: number;
  results: Array<{
    burn_block_time: number;
    burn_block_time_iso: string;
    burn_block_hash: string;
    burn_block_height: number;
    stacks_blocks: Array<string>;
  }>;
}

Supports the filters:

  • ?height=<burn block height
  • ?hash=<burn block hash>
  • ?hash=latest -- returns the latest burn block
  • ?limit=n&offset=b

Example:

curl -s http://localhost:3999/extended/v1/burn_block | jq
{
  "limit": 20,
  "offset": 0,
  "total": 9,
  "results": [
    {
      "burn_block_time": 1683536586,
      "burn_block_time_iso": "2023-05-08T09:03:06.000Z",
      "burn_block_hash": "0x7ba962d9a6b03f6de757bb296c20080bd7ef797cbca7baa48e9e187a0c50e0d1",
      "burn_block_height": 111,
      "stacks_blocks": [
        "0x5db3883b0b8c837263d7ca93e06cdc58e679479717080e224c903ee7fdd8c375"
      ]
    },
    {
      "burn_block_time": 1683536584,
      "burn_block_time_iso": "2023-05-08T09:03:04.000Z",
      "burn_block_hash": "0x778b32885bf0ec92ac5e3168eb0d0b27150a3024ecf447b38dadc420f5a80c12",
      "burn_block_height": 110,
      "stacks_blocks": [
        "0x9569e4eff2b192b9ec2c36d19a5b82a9e57ae58d40ec588dd9d061331db3dfaa"
      ]
    },
    {
      "burn_block_time": 1683536582,
      "burn_block_time_iso": "2023-05-08T09:03:02.000Z",
      "burn_block_hash": "0x66bf54781cf61ed7a01c20a742d3cb775805141c76a1432bc0f0f45b0b41557b",
      "burn_block_height": 109,
      "stacks_blocks": [
        "0x3fcd0e58739ac43ddcf564efd3015be952ee2d00120672ec832c45b734e59ba2"
      ]
    },
    {
      "burn_block_time": 1683536580,
      "burn_block_time_iso": "2023-05-08T09:03:00.000Z",
      "burn_block_hash": "0x0fd30f565101416b59840b459d2aee3f82472d1e74df02a3799005445b4d1f0b",
      "burn_block_height": 108,
      "stacks_blocks": [
        "0xef83e86f8ca0d40a643fdfb26fe5387ae24408029e573b8abc7a041e39fe6fe4"
      ]
    },
    {
      "burn_block_time": 1683536578,
      "burn_block_time_iso": "2023-05-08T09:02:58.000Z",
      "burn_block_hash": "0x1a1f91873d908d3c5ac52542849e7f9d1d788a0b9789e72bff451b42b3c84100",
      "burn_block_height": 107,
      "stacks_blocks": [
        "0xed2ad08d0a2eaf641c3556071d8e418c8c5a03015914f7a5e994c6e23a7f70ff"
      ]
    },
    {
      "burn_block_time": 1683536575,
      "burn_block_time_iso": "2023-05-08T09:02:55.000Z",
      "burn_block_hash": "0x56076c828cf18aaf92c54bda771bd97b77d4a1f369dd643893460728f5d8c8bf",
      "burn_block_height": 106,
      "stacks_blocks": [
        "0x0fbb87d301318960a94042ea5c820faf4eb30252ad80c0e2121d398fb31d006b"
      ]
    },
    {
      "burn_block_time": 1683536573,
      "burn_block_time_iso": "2023-05-08T09:02:53.000Z",
      "burn_block_hash": "0x13d52058dff508eab4596cc37d1439784e83ce260b3fd156590e06e7f26f60eb",
      "burn_block_height": 105,
      "stacks_blocks": [
        "0x32dba671d066d552d646ab74f7222b54d96c8c07ab578f8635b51fd86fcb3d48"
      ]
    },
    {
      "burn_block_time": 1683536571,
      "burn_block_time_iso": "2023-05-08T09:02:51.000Z",
      "burn_block_hash": "0x204ed0d2be59a32d3f8420e7f8b6e0a9b3ac15bf98b78a23dabbba0345f3ca41",
      "burn_block_height": 104,
      "stacks_blocks": [
        "0x14203aa894853490e763cfdc648eb614e1428a2a7b52613230cf6aed7853e9eb"
      ]
    },
    {
      "burn_block_time": 1683536569,
      "burn_block_time_iso": "2023-05-08T09:02:49.000Z",
      "burn_block_hash": "0x415531a5b0fdcc2b6bba4d389fc21115d4dac30805cc1426acb1f92b0c5ec11c",
      "burn_block_height": 103,
      "stacks_blocks": [
        "0xaf27933596ed33e239359eb8a33818e3c9f56919b508dcab3d9abca9bbda6c65"
      ]
    }
  ]
}

@zone117x zone117x requested review from He1DAr and rafaelcr December 12, 2023 14:06
@zone117x zone117x changed the title Feat/get burn blocks feat: GET /extended/v1/burn_block Dec 12, 2023
@zone117x zone117x linked an issue Dec 12, 2023 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Dec 12, 2023

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

@codecov
Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 59 lines in your changes are missing coverage. Please review.

Comparison is base (7c45f53) 70.84% compared to head (f958cb3) 17.32%.

Files Patch % Lines
src/api/routes/burn-block.ts 0.00% 22 Missing and 1 partial ⚠️
src/api/query-helpers.ts 0.00% 11 Missing and 3 partials ⚠️
src/datastore/pg-store.ts 0.00% 13 Missing ⚠️
src/api/controllers/db-controller.ts 14.28% 6 Missing ⚠️
src/api/init.ts 0.00% 2 Missing ⚠️
src/api/pagination.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           nakamoto    #1766       +/-   ##
=============================================
- Coverage     70.84%   17.32%   -53.52%     
=============================================
  Files            86       87        +1     
  Lines         11541    11601       +60     
  Branches       2516     2532       +16     
=============================================
- Hits           8176     2010     -6166     
- Misses         3213     8929     +5716     
- Partials        152      662      +510     

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

router.use('/tx', createTxRouter(datastore));
router.use('/block', createBlockRouter(datastore));
router.use('/microblock', createMicroblockRouter(datastore));
router.use('/burn_block', createBurnBlockRouter(datastore));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we move this to the /v2 group? Given that it's a new endpoint aimed at Nakamoto functionality (and we'll probably be adding more endpoints there in the future, including the stacks blocks one I'm working on). IMO it should be /extended/v2/burn_blocks in plural to make it more RESTful

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we change this this route to /v2, we should move this file to a v2/ folder

ORDER BY block_height DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS stacks_blocks
FROM blocks
Copy link
Collaborator

Choose a reason for hiding this comment

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

From what I see in this query, we're only going to be returning burn blocks that contain Stacks blocks, right? If we receive a /new_burn_block message that doesn't correspond to a Stacks block, we won't be returning that one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep that's correct. The /new_burn_block event is missing some properties and is unreliable. Explorer team is aware of this limitation -- they'll need to use a proper bitcoin indexer for more btc data

@zone117x
Copy link
Contributor Author

Merging, and we'll move it over to /extended/v2 in the PR for #1755

@zone117x zone117x merged commit cb38b68 into nakamoto Dec 12, 2023
@zone117x zone117x deleted the feat/get-burn-blocks branch December 12, 2023 16:12
blockstack-devops pushed a commit that referenced this pull request Dec 13, 2023
## [7.4.0-nakamoto.3](v7.4.0-nakamoto.2...v7.4.0-nakamoto.3) (2023-12-13)

### Features

* `GET /extended/v1/burn_block` ([#1766](#1766)) ([cb38b68](cb38b68))
* ingestion for `TenureChange` and `NakamotoCoinbase` tx types ([#1753](#1753)) ([7c45f53](7c45f53))
* pox-4 support ([#1754](#1754)) ([285806f](285806f))
@blockstack-devops
Copy link
Contributor

🎉 This PR is included in version 7.4.0-nakamoto.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Jan 9, 2024
## [7.6.0-nakamoto.1](v7.5.0...v7.6.0-nakamoto.1) (2024-01-09)

### Features

* `GET /extended/v1/burn_block` ([#1766](#1766)) ([cb38b68](cb38b68))
* add `/extended/v2/blocks/:height_or_hash` ([#1774](#1774)) ([e532a5e](e532a5e))
* add `/extended/v2/blocks` endpoint with burn block filters ([#1769](#1769)) ([ceb7be0](ceb7be0))
* add `tx_count` property to `/extended/v2/blocks` ([#1778](#1778)) ([da4cd56](da4cd56))
* add dataset store ([4211328](4211328))
* add step to compile duckdb for Alpine image ([0f40e14](0f40e14))
* better handling of raw events insertion ([bb70ca9](bb70ca9))
* create `/extended/v2/burn-blocks/:height_or_hash/blocks` endpoint ([#1782](#1782)) ([20466a1](20466a1))
* disable rosetta via an ENV var ([#1804](#1804)) ([2d2aee3](2d2aee3))
* event-replay new_block events handling ([1708b42](1708b42))
* event-replay new_burn_block events handling ([6c0f448](6c0f448))
* event-replay raw events handling ([81f43cf](81f43cf))
* event-replay remainder events handling ([3ede07f](3ede07f))
* event-replay supporting parallel insertions ([f33ecee](f33ecee))
* events folder as environment var ([701bd1a](701bd1a))
* ingestion for `TenureChange` and `NakamotoCoinbase` tx types ([#1753](#1753)) ([7c45f53](7c45f53))
* parallel processing using node cluster ([d02a7e8](d02a7e8))
* pox-4 support ([#1754](#1754)) ([285806f](285806f))
* processing raw events in parallel ([7a6f241](7a6f241))
* update to latest TenureChange tx payload ([#1767](#1767)) ([2afb65c](2afb65c))

### Bug Fixes

* add token offering ([8ef039e](8ef039e))
* allow contract-principals in `/extended/v1/address/:principal/mempool` endpoint [#1685](#1685) ([#1704](#1704)) ([163b76a](163b76a))
* better args handlling ([c77ac57](c77ac57))
* better path handling for workers ([1bd8f17](1bd8f17))
* changed processing order ([62a12bd](62a12bd))
* convert `chain_tip` materialized view into a table ([#1751](#1751)) ([04b71cc](04b71cc))
* do not load duckdb binary unless required ([#1776](#1776)) ([db859ae](db859ae))
* flaky test ([484d2ea](484d2ea))
* flaky test ([65175f5](65175f5))
* handle `Problematic` status in `/drop_mempool_tx` event ([#1790](#1790)) ([ce9b38f](ce9b38f))
* import statement in replay controller ([7a10cd8](7a10cd8))
* insert block transaction data in batches ([#1760](#1760)) ([bf99e90](bf99e90))
* lint ([01589ea](01589ea))
* lint ([82eadcb](82eadcb))
* lint ([8c67ae5](8c67ae5))
* move `/extended/v1/burn_block` to `/extended/v2/burn-blocks` ([#1772](#1772)) ([bf2ef0a](bf2ef0a))
* on attachments_new events processing ([0707313](0707313))
* optimize mempool transaction reads and writes ([#1781](#1781)) ([3a02f57](3a02f57))
* re-enable indexes when finishing the replay ([fc379eb](fc379eb))
* remove dangling promise ([62a48ae](62a48ae))
* remove deprecated token endpoints ([#1775](#1775)) ([18f74b7](18f74b7))
* revert configurable DB index type ([86154b2](86154b2))
* upgrade semver package to fix ReDoS vulnerability ([6b1605b](6b1605b))
* vercel preview builds ([#1783](#1783)) ([d36b1c2](d36b1c2))
@blockstack-devops
Copy link
Contributor

🎉 This PR is included in version 7.6.0-nakamoto.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Jan 9, 2024
## [7.6.0](v7.5.0...v7.6.0) (2024-01-09)

### Features

* `GET /extended/v1/burn_block` ([#1766](#1766)) ([cb38b68](cb38b68))
* add `/extended/v2/blocks/:height_or_hash` ([#1774](#1774)) ([e532a5e](e532a5e))
* add `/extended/v2/blocks` endpoint with burn block filters ([#1769](#1769)) ([ceb7be0](ceb7be0))
* add `order_by` and `order` params to `/extended/v1/tx/mempool` ([#1810](#1810)) ([2d45b2e](2d45b2e))
* add `tx_count` property to `/extended/v2/blocks` ([#1778](#1778)) ([da4cd56](da4cd56))
* add dataset store ([4211328](4211328))
* add step to compile duckdb for Alpine image ([0f40e14](0f40e14))
* better handling of raw events insertion ([bb70ca9](bb70ca9))
* create `/extended/v2/burn-blocks/:height_or_hash/blocks` endpoint ([#1782](#1782)) ([20466a1](20466a1))
* disable rosetta via an ENV var ([#1804](#1804)) ([2d2aee3](2d2aee3))
* event-replay new_block events handling ([1708b42](1708b42))
* event-replay new_burn_block events handling ([6c0f448](6c0f448))
* event-replay raw events handling ([81f43cf](81f43cf))
* event-replay remainder events handling ([3ede07f](3ede07f))
* event-replay supporting parallel insertions ([f33ecee](f33ecee))
* events folder as environment var ([701bd1a](701bd1a))
* ingestion for `TenureChange` and `NakamotoCoinbase` tx types ([#1753](#1753)) ([7c45f53](7c45f53))
* parallel processing using node cluster ([d02a7e8](d02a7e8))
* pox-4 support ([#1754](#1754)) ([285806f](285806f))
* processing raw events in parallel ([7a6f241](7a6f241))
* support tenure_change in tx type filter queries ([#1808](#1808)) ([0831393](0831393))
* update to latest TenureChange tx payload ([#1767](#1767)) ([2afb65c](2afb65c))

### Bug Fixes

* add token offering ([8ef039e](8ef039e))
* allow contract-principals in `/extended/v1/address/:principal/mempool` endpoint [#1685](#1685) ([#1704](#1704)) ([163b76a](163b76a))
* better args handlling ([c77ac57](c77ac57))
* better path handling for workers ([1bd8f17](1bd8f17))
* changed processing order ([62a12bd](62a12bd))
* convert `chain_tip` materialized view into a table ([#1751](#1751)) ([04b71cc](04b71cc))
* do not load duckdb binary unless required ([#1776](#1776)) ([db859ae](db859ae))
* **docs:** URL query arrays should be formatted with `form` rather than comma-separated ([#1807](#1807)) ([e184fb5](e184fb5))
* flaky test ([484d2ea](484d2ea))
* flaky test ([65175f5](65175f5))
* handle `Problematic` status in `/drop_mempool_tx` event ([#1790](#1790)) ([ce9b38f](ce9b38f))
* import statement in replay controller ([7a10cd8](7a10cd8))
* insert block transaction data in batches ([#1760](#1760)) ([bf99e90](bf99e90))
* lint ([01589ea](01589ea))
* lint ([82eadcb](82eadcb))
* lint ([8c67ae5](8c67ae5))
* move `/extended/v1/burn_block` to `/extended/v2/burn-blocks` ([#1772](#1772)) ([bf2ef0a](bf2ef0a))
* on attachments_new events processing ([0707313](0707313))
* optimize mempool transaction reads and writes ([#1781](#1781)) ([3a02f57](3a02f57))
* re-enable indexes when finishing the replay ([fc379eb](fc379eb))
* remove dangling promise ([62a48ae](62a48ae))
* remove deprecated token endpoints ([#1775](#1775)) ([18f74b7](18f74b7))
* revert configurable DB index type ([86154b2](86154b2))
* support comma-separated strings in array query params ([#1809](#1809)) ([c9a4df8](c9a4df8))
* upgrade semver package to fix ReDoS vulnerability ([6b1605b](6b1605b))
* vercel preview builds ([#1783](#1783)) ([d36b1c2](d36b1c2))
@blockstack-devops
Copy link
Contributor

🎉 This PR is included in version 7.6.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.

Get burn blocks

4 participants