Skip to content

Commit 9648ac8

Browse files
authored
feat: add burn_block_height to Rosetta endpoints (#1974)
1 parent a72bfbd commit 9648ac8

File tree

9 files changed

+57
-34
lines changed

9 files changed

+57
-34
lines changed

docker/docker-compose.dev.stacks-blockchain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: 'hirosystems/stacks-api-e2e:stacks3.0-4d11d85'
4+
image: 'hirosystems/stacks-api-e2e:stacks3.0-0a2c0e2'
55
restart: on-failure
66
environment:
77
STACKS_EVENT_OBSERVER: host.docker.internal:3700

docker/docker-compose.dev.stacks-krypton.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.7'
22
services:
33
stacks-blockchain:
4-
image: 'hirosystems/stacks-api-e2e:stacks3.0-4d11d85'
4+
image: 'hirosystems/stacks-api-e2e:stacks3.0-0a2c0e2'
55
ports:
66
- '18443:18443' # bitcoin regtest JSON-RPC interface
77
- '18444:18444' # bitcoin regtest p2p

docs/api/rosetta/rosetta-network-status-response.schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"current_block_identifier",
77
"current_block_timestamp",
88
"genesis_block_identifier",
9-
"peers"
9+
"peers",
10+
"current_burn_block_height"
1011
],
1112
"properties": {
1213
"current_block_identifier": {
@@ -31,6 +32,10 @@
3132
"items": {
3233
"$ref": "./../../entities/rosetta/rosetta-network-peers.schema.json"
3334
}
35+
},
36+
"current_burn_block_height": {
37+
"type": "integer",
38+
"description": "The latest burn block height"
3439
}
3540
},
3641
"additionalProperties": false

docs/entities/rosetta/rosetta-block.schema.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"type": "object",
33
"title": "RosettaBlock",
44
"description": "Blocks contain an array of Transactions that occurred at a particular BlockIdentifier. A hard requirement for blocks returned by Rosetta implementations is that they MUST be inalterable: once a client has requested and received a block identified by a specific BlockIndentifier, all future calls for that same BlockIdentifier must return the same block contents.",
5-
"required": ["block_identifier", "parent_block_identifier", "timestamp", "transactions"],
5+
"required": ["block_identifier", "parent_block_identifier", "timestamp", "transactions", "metadata"],
66
"additionalProperties": false,
77
"properties": {
88
"block_identifier": {
@@ -25,14 +25,10 @@
2525
"metadata": {
2626
"type": "object",
2727
"description": "meta data",
28-
"required": ["transactions_root", "difficulty"],
28+
"required": ["burn_block_height"],
2929
"properties": {
30-
"transactions_root": {
31-
"type": "string",
32-
"description": ""
33-
},
34-
"difficulty": {
35-
"type": "string",
30+
"burn_block_height": {
31+
"type": "number",
3632
"description": ""
3733
}
3834
}

docs/generated.d.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ export type AbstractTransaction = BaseTransaction & {
440440
* An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined.
441441
*/
442442
block_time_iso: string;
443+
/**
444+
* Height of the anchor burn block.
445+
*/
443446
burn_block_height: number;
444447
/**
445448
* Unix timestamp (in seconds) indicating when this block was mined
@@ -2361,9 +2364,8 @@ export interface RosettaBlock {
23612364
/**
23622365
* meta data
23632366
*/
2364-
metadata?: {
2365-
transactions_root: string;
2366-
difficulty: string;
2367+
metadata: {
2368+
burn_block_height: number;
23672369
[k: string]: unknown | undefined;
23682370
};
23692371
}
@@ -3029,6 +3031,10 @@ export interface RosettaNetworkStatusResponse {
30293031
* Peers information
30303032
*/
30313033
peers: RosettaPeers[];
3034+
/**
3035+
* The latest burn block height
3036+
*/
3037+
current_burn_block_height: number;
30323038
}
30333039
/**
30343040
* The block_identifier uniquely identifies a block in a particular network.

src/api/controllers/db-controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ export async function getRosettaBlockFromDataStore(
518518
parent_block_identifier,
519519
timestamp: dbBlock.burn_block_time * 1000,
520520
transactions: blockTxs.found ? blockTxs.result : [],
521+
metadata: {
522+
burn_block_height: dbBlock.burn_block_height,
523+
},
521524
};
522525
return { found: true, result: apiBlock };
523526
});

src/api/routes/rosetta/network.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export function createRosettaNetworkRouter(db: PgStore, chainId: ChainID): expre
9898
hash: genesis.block_identifier.hash,
9999
},
100100
peers,
101+
current_burn_block_height: block.metadata?.burn_block_height ?? 0,
101102
};
102103
const nodeInfo = await stacksCoreRpcClient.getInfo();
103104
const referenceNodeTipHeight = nodeInfo.stacks_tip_height;

src/tests-rosetta/api.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {
1111
RosettaAccountBalanceRequest,
1212
RosettaAccountBalanceResponse,
1313
RosettaAmount,
14+
RosettaBlockResponse,
1415
RosettaMempoolRequest,
1516
RosettaMempoolResponse,
1617
RosettaMempoolTransactionRequest,
1718
RosettaMempoolTransactionResponse,
19+
RosettaNetworkStatusResponse,
1820
RosettaOperation,
1921
RosettaTransaction,
2022
} from '@stacks/stacks-blockchain-api-types';
@@ -133,7 +135,8 @@ describe('Rosetta API', () => {
133135
parent_block_hash: genesisData.block.block_hash,
134136
parent_index_block_hash: genesisData.block.index_block_hash,
135137
block_height: 2,
136-
index_block_hash: '0x12345678'
138+
index_block_hash: '0x12345678',
139+
burn_block_height: 13334,
137140
}
138141
const blockData = new TestBlockBuilder(blockBuilderData).build();
139142

@@ -172,7 +175,7 @@ describe('Rosetta API', () => {
172175
expect(query1.status).toBe(200);
173176
expect(query1.type).toBe('application/json');
174177

175-
const expectResponse = {
178+
const expectResponse: RosettaNetworkStatusResponse = {
176179
current_block_identifier: {
177180
index: block.block_height,
178181
hash: block.block_hash,
@@ -183,18 +186,14 @@ describe('Rosetta API', () => {
183186
hash: genesisBlock.block_hash,
184187
},
185188
peers: [],
189+
current_burn_block_height: blockBuilderData.burn_block_height,
190+
sync_status: {
191+
current_index: 2,
192+
synced: true,
193+
target_index: 2,
194+
}
186195
};
187-
188-
expect(JSON.parse(query1.text)).toHaveProperty('sync_status');
189-
expect(JSON.parse(query1.text).current_block_identifier).toEqual(
190-
expectResponse.current_block_identifier
191-
);
192-
expect(JSON.parse(query1.text).current_block_timestamp).toEqual(
193-
expectResponse.current_block_timestamp
194-
);
195-
expect(JSON.parse(query1.text).genesis_block_identifier).toEqual(
196-
expectResponse.genesis_block_identifier
197-
);
196+
expect(query1.body).toEqual(expectResponse);
198197
});
199198

200199
test('block - by index', async () => {
@@ -224,7 +223,7 @@ describe('Rosetta API', () => {
224223
});
225224
expect(query1.status).toBe(200);
226225
expect(query1.type).toBe('application/json');
227-
expect(JSON.parse(query1.text)).toEqual({
226+
const expected: RosettaBlockResponse = {
228227
block: {
229228
block_identifier: {
230229
index: blockHeight,
@@ -250,8 +249,12 @@ describe('Rosetta API', () => {
250249
],
251250
},
252251
],
252+
metadata: {
253+
burn_block_height: data.block.burn_block_height,
254+
}
253255
},
254-
});
256+
};
257+
expect(JSON.parse(query1.text)).toEqual(expected);
255258
});
256259

257260
test('block - by hash', async () => {
@@ -281,7 +284,7 @@ describe('Rosetta API', () => {
281284
});
282285
expect(query1.status).toBe(200);
283286
expect(query1.type).toBe('application/json');
284-
expect(JSON.parse(query1.text)).toEqual({
287+
const expected: RosettaBlockResponse = {
285288
block: {
286289
block_identifier: {
287290
index: blockHeight,
@@ -307,8 +310,12 @@ describe('Rosetta API', () => {
307310
],
308311
},
309312
],
313+
metadata: {
314+
burn_block_height: data.block.burn_block_height,
315+
}
310316
},
311-
});
317+
};
318+
expect(JSON.parse(query1.text)).toEqual(expected);
312319
});
313320

314321
test('block - get latest', async () => {
@@ -327,6 +334,7 @@ describe('Rosetta API', () => {
327334
block_height: 2,
328335
burn_block_time: 94869286,
329336
burn_block_hash: '0xfe15c0d3ebe314fad720a08b839a004c2e6386f5aecc19ec74807d1920cb6aeb',
337+
burn_block_height: 1222,
330338
}
331339

332340
await db.update(new TestBlockBuilder(block1).addTx().build());
@@ -341,7 +349,7 @@ describe('Rosetta API', () => {
341349

342350
expect(query1.status).toBe(200);
343351
expect(query1.type).toBe('application/json');
344-
expect(JSON.parse(query1.text)).toEqual({
352+
const expected: RosettaBlockResponse = {
345353
block: {
346354
block_identifier: {
347355
index: block2.block_height,
@@ -353,8 +361,12 @@ describe('Rosetta API', () => {
353361
},
354362
timestamp: block2.burn_block_time * 1000,
355363
transactions: expect.objectContaining({}),
364+
metadata: {
365+
burn_block_height: block2.burn_block_height,
366+
}
356367
},
357-
});
368+
};
369+
expect(JSON.parse(query1.text)).toEqual(expected);
358370
});
359371

360372
test('block/transaction', async () => {

stacks-blockchain/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Pointed to stacks-blockchain `2.1.0.0.0` git tag
2-
FROM --platform=linux/amd64 hirosystems/stacks-api-e2e:stacks3.0-4d11d85 as build
2+
FROM --platform=linux/amd64 hirosystems/stacks-api-e2e:stacks3.0-0a2c0e2 as build
33

44
FROM --platform=linux/amd64 debian:bookworm
55

0 commit comments

Comments
 (0)