Skip to content

Commit e6487f6

Browse files
authored
Merge pull request #6431 from rdeioris/feat/tenureblocks_endpoint
Added /v3/tenures/blocks/{consensus_hash} endpoint
2 parents ab6459b + 8d4218c commit e6487f6

File tree

9 files changed

+667
-0
lines changed

9 files changed

+667
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1111

1212
- Add `stackerdb_timeout_secs` to miner config for limiting duration of StackerDB HTTP requests.
1313
- When determining a global transaction replay set, the state evaluator now uses a longest-common-prefix algorithm to find a replay set in the case where a single replay set has less than 70% of signer weight.
14+
- New endpoint /v3/tenures/blocks/ allowing retrieving the list of stacks blocks from a burn block
1415

1516
### Changed
1617

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"burn_block_hash": "dff0aba3d65209225e365692ac46d26fa64ca9760bd7c244fc27e2022f7cb90d",
3+
"burn_block_height": 51,
4+
"consensus_hash": "90b360130732dd83a165a7fa34386ae547512300",
5+
"stacks_blocks": [
6+
{
7+
"block_hash": "a9f3d8bca7d766a2022528e27c52f39ba77192f0712ea5515cc9d06b97821a11",
8+
"block_id": "67c795896b4c2940b3eb759871661a72e78458ba591dc63979d689d23695891f",
9+
"header_type": "nakamoto",
10+
"height": 116,
11+
"parent_block_id": "fb7102c45bb2f07a6dd86b6672cb39133861fc7d38087e82cb04d4faccfcab82"
12+
},
13+
{
14+
"block_hash": "3e81505acaa3d386e15256921dd1193e479fd9d7f81d993b1c2b327b9bfb05cc",
15+
"block_id": "fb7102c45bb2f07a6dd86b6672cb39133861fc7d38087e82cb04d4faccfcab82",
16+
"header_type": "nakamoto",
17+
"height": 115,
18+
"parent_block_id": "5d51f815bc71508768b71258d8bc2adc68c129428101a418083f5b5ab30d525e"
19+
},
20+
{
21+
"block_hash": "c6f427503dcbe8bf187c7ce523c7a239328b2ab4ec87d6013895b2bd9ed23604",
22+
"block_id": "5d51f815bc71508768b71258d8bc2adc68c129428101a418083f5b5ab30d525e",
23+
"header_type": "nakamoto",
24+
"height": 114,
25+
"parent_block_id": "7d1c89f57a467f888fed171a5b3a2e51a7652f862189710df7db814ef84a29e2"
26+
},
27+
{
28+
"block_hash": "f0665d1dd419e949d68c4e85b7f79e078d6c36d929820b9cd9c794a60c0505b4",
29+
"block_id": "7d1c89f57a467f888fed171a5b3a2e51a7652f862189710df7db814ef84a29e2",
30+
"header_type": "nakamoto",
31+
"height": 113,
32+
"parent_block_id": "b65ab3b6d113285390c1d99c09a62d940f5b55c1cbc10bdc1b478c395fc435f9"
33+
},
34+
{
35+
"block_hash": "0486701e4eed06b74c3d93b82ffc0f3700b3cb2bea41aea1a30e00a5669ec0b7",
36+
"block_id": "b65ab3b6d113285390c1d99c09a62d940f5b55c1cbc10bdc1b478c395fc435f9",
37+
"header_type": "nakamoto",
38+
"height": 112,
39+
"parent_block_id": "c711415e6eedffcb6be16e33eb5c5cf62c3f51047f9528a51e21cbd83b25c185"
40+
},
41+
{
42+
"block_hash": "6724170340a2e507dbe7b21b691412e196c7c8900a597786aa991c1429ae6b58",
43+
"block_id": "c711415e6eedffcb6be16e33eb5c5cf62c3f51047f9528a51e21cbd83b25c185",
44+
"header_type": "nakamoto",
45+
"height": 111,
46+
"parent_block_id": "b11d631ef1b052942973cac88527a56f6e00c51fd57f9b7a710713f58ddc2393"
47+
},
48+
{
49+
"block_hash": "2114066e4446242e558847f552ca839f65ae769ab59000087677007e52b0dab7",
50+
"block_id": "b11d631ef1b052942973cac88527a56f6e00c51fd57f9b7a710713f58ddc2393",
51+
"header_type": "nakamoto",
52+
"height": 110,
53+
"parent_block_id": "2ef1973e95ba622479e59e87251d35c1eaaa9cb7f99f3dd3a8a79359624c38eb"
54+
},
55+
{
56+
"block_hash": "2345d34722cb07e908c5dab7f89ec0756f34d7fe34c86e40881c29c6aa202601",
57+
"block_id": "2ef1973e95ba622479e59e87251d35c1eaaa9cb7f99f3dd3a8a79359624c38eb",
58+
"header_type": "nakamoto",
59+
"height": 109,
60+
"parent_block_id": "9c1f844267819dc7349ff0aff6e6c6f60d8c41b531e304cd89df022ca4d147bf"
61+
},
62+
{
63+
"block_hash": "6b904297fdd045e2d18b93083f9d36592fa6915a53e8461fc3b4c59f6c91bc6d",
64+
"block_id": "9c1f844267819dc7349ff0aff6e6c6f60d8c41b531e304cd89df022ca4d147bf",
65+
"header_type": "nakamoto",
66+
"height": 108,
67+
"parent_block_id": "335596dd153bfc155863a2d439940816cd5095a3b36e2738fb89d715c28ac6c5"
68+
},
69+
{
70+
"block_hash": "cd748c67a9b7e685c52f388cc1d5e334b3dbe2509535caaf9f7ea7b6e5bbad77",
71+
"block_id": "335596dd153bfc155863a2d439940816cd5095a3b36e2738fb89d715c28ac6c5",
72+
"header_type": "nakamoto",
73+
"height": 107,
74+
"parent_block_id": "45cb658a80897117c2cfa6191a7623344ed1079117ad8bb30113019278bac028"
75+
}
76+
]
77+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
type: object
2+
properties:
3+
consensus_hash:
4+
type: string
5+
description: Consensus hash of the tenure
6+
pattern: "^[0-9a-f]{40}$"
7+
burn_block_height:
8+
type: integer
9+
description: Height of the Bitcoin block
10+
format: uint64
11+
burn_block_hash:
12+
type: string
13+
description: Hash of the Bitcoin block
14+
pattern: "^[0-9a-f]{64}$"
15+
stacks_blocks:
16+
type: array
17+
items:
18+
type: object
19+
properties:
20+
block_id:
21+
type: string
22+
description: Block ID (index block hash)
23+
pattern: "^[0-9a-f]{64}$"
24+
block_hash:
25+
type: string
26+
description: Hash of the block
27+
pattern: "^[0-9a-f]{64}$"
28+
header_type:
29+
type: string
30+
description: Type of block (currently "epoch2" or "nakamoto")
31+
height:
32+
type: integer
33+
description: Height of the block
34+
format: uint64
35+
parent_block_id:
36+
type: string
37+
description: Block ID (index block hash) of the parent
38+
pattern: "^[0-9a-f]{64}$"
39+

docs/rpc/openapi.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ components:
157157
$ref: ./components/schemas/tenure-tip.schema.yaml
158158
GetStackerSet:
159159
$ref: ./components/schemas/get-stacker-set.schema.yaml
160+
TenureBlocks:
161+
$ref: ./components/schemas/tenure-blocks.schema.yaml
160162

161163
paths:
162164
/v2/transactions:
@@ -1057,6 +1059,40 @@ paths:
10571059
type: string
10581060
format: binary
10591061

1062+
/v3/tenures/blocks/{consensus_hash}:
1063+
get:
1064+
summary: Get the list of Stacks blocks in a tenure
1065+
tags:
1066+
- Blocks
1067+
security: []
1068+
operationId: getTenureBlocks
1069+
description: |
1070+
Get the list of blocks in a tenure. The blocks will be
1071+
shown in order from highest to lowest.
1072+
parameters:
1073+
- name: consensus_hash
1074+
in: path
1075+
description: The hex-encoded consensus hash of the tenure to query (40 hexadecimal characters, without 0x prefix)
1076+
required: true
1077+
schema:
1078+
type: string
1079+
pattern: "^[0-9a-f]{40}$"
1080+
responses:
1081+
"200":
1082+
description: List of Stacks blocks in the tenure
1083+
content:
1084+
application/json:
1085+
schema:
1086+
$ref: "#/components/schemas/TenureBlocks"
1087+
example:
1088+
$ref: "./components/examples/tenure-blocks.example.json"
1089+
"400":
1090+
$ref: "#/components/responses/BadRequest"
1091+
"404":
1092+
$ref: "#/components/responses/NotFound"
1093+
"500":
1094+
$ref: "#/components/responses/InternalServerError"
1095+
10601096
/v3/sortitions:
10611097
get:
10621098
summary: Get latest sortition information

stackslib/src/chainstate/stacks/db/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ impl StacksHeaderInfo {
395395
pub fn is_nakamoto_block(&self) -> bool {
396396
matches!(self.anchored_header, StacksBlockHeaderTypes::Nakamoto(_))
397397
}
398+
399+
pub fn header_type_name(&self) -> &str {
400+
match self.anchored_header {
401+
StacksBlockHeaderTypes::Epoch2(_) => "epoch2",
402+
StacksBlockHeaderTypes::Nakamoto(_) => "nakamoto",
403+
}
404+
}
398405
}
399406

400407
impl FromRow<DBConfig> for DBConfig {

0 commit comments

Comments
 (0)