Skip to content

Commit

Permalink
feat: #302 add btc info to blocks, #301 pull stacks-node from dockerh…
Browse files Browse the repository at this point in the history
…ub image
  • Loading branch information
zone117x committed Oct 27, 2020
1 parent e6e445b commit 9e9fd99
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 34 deletions.
2 changes: 1 addition & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ services:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: stacks_blockchain_api
POSTGRES_PORT: 5432
volumes:
- database-data:/var/lib/postgresql/data/ # persist data even if container shuts down
networks:
- backend
stacks-blockchain:
Expand Down Expand Up @@ -60,6 +58,3 @@ services:

networks:
backend:

volumes:
database-data:
3 changes: 3 additions & 0 deletions docs/entities/blocks/block.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"parent_block_hash": "0x75ab21ef25cbff2caa14c27d830ed7886a4d1522e1b6f9e5dc3b59ccf73ed49f",
"burn_block_time": 1594233639,
"burn_block_time_iso": "2020-08-27T16:41:26.000Z",
"burn_block_hash": "0xb154c008df2101023a6d0d54986b3964cee58119eed14f5bed98e15678e18fe2",
"burn_block_height": 654439,
"miner_txid": "0xd7d56070277ccd87b42acf0c91f915dd181f9db4cf878a4e95518bc397c240cc",
"txs": ["0x66557c219c6b0cdb40681ecf79a69f03654d88ef1910651a7db0b078f58af5ca"]
}
16 changes: 14 additions & 2 deletions docs/entities/blocks/block.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Block",
"description": "A block",
"type": "object",
"required": ["canonical", "height", "hash", "parent_block_hash", "txs", "burn_block_time", "burn_block_time_iso"],
"required": ["canonical", "height", "hash", "parent_block_hash", "txs", "burn_block_time", "burn_block_time_iso", "burn_block_hash", "burn_block_height", "miner_txid"],
"properties": {
"canonical": {
"type": "boolean",
Expand All @@ -19,7 +19,7 @@
},
"parent_block_hash": {
"type": "string",
"description": "Hash of the prant block"
"description": "Hash of the parent block"
},
"burn_block_time": {
"type": "number",
Expand All @@ -29,6 +29,18 @@
"type": "string",
"description": "An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined."
},
"burn_block_hash": {
"type": "string",
"description": "Hash of the anchor chain block"
},
"burn_block_height": {
"type": "integer",
"description": "Height of the anchor chain block"
},
"miner_txid": {
"type": "string",
"description": "Anchor chain transaction ID"
},
"txs": {
"type": "array",
"description": "List of transactions included in the block",
Expand Down
14 changes: 13 additions & 1 deletion docs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ export interface Block {
*/
hash: string;
/**
* Hash of the prant block
* Hash of the parent block
*/
parent_block_hash: string;
/**
Expand All @@ -707,6 +707,18 @@ export interface Block {
* An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined.
*/
burn_block_time_iso: string;
/**
* Hash of the anchor chain block
*/
burn_block_hash: string;
/**
* Height of the anchor chain block
*/
burn_block_height: number;
/**
* Anchor chain transaction ID
*/
miner_txid: string;
/**
* List of transactions included in the block
*/
Expand Down
13 changes: 2 additions & 11 deletions follower.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ RUN npm install
RUN npm run build
RUN npm prune --production


### Fetch stacks-node binary
FROM everpeace/curl-jq as stacks-node-build
ENV ARTIFACTS "http://blockstack-stacks-blockchain_artifacts.storage.googleapis.com/index.json"
RUN curl -s "$ARTIFACTS" --output ./artifacts-resp.json \
&& cat ./artifacts-resp.json | jq -r '."stacks-node-krypton"."linux-x64".latest.url' > ./url \
&& mkdir -p /app \
&& echo "Fetching $(cat ./url)" \
&& curl --compressed $(cat ./url) --output /stacks-node \
&& chmod +x /stacks-node

FROM blockstack/stacks-blockchain:v23.0.0.10-krypton-stretch as stacks-node-build

### Begin building base image
FROM ubuntu:focal
Expand Down Expand Up @@ -53,7 +44,7 @@ ENV PATH=$PATH:/home/stacky/.nvm/versions/node/v${NODE_VERSION}/bin
RUN node -e 'console.log("Node.js runs")'

### Setup stacks-node
COPY --from=stacks-node-build /stacks-node stacks-node/
COPY --from=stacks-node-build /bin/stacks-node stacks-node/
ENV PATH="$PATH:$HOME/stacks-node"

#### Copy stacks-node mocknet config
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devenv:follower": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain-follower.yml up",
"devenv:stop": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain.yml -f docker-compose.dev.bitcoind.yml down -v -t 0",
"devenv:logs": "docker-compose -f docker-compose.dev.postgres.yml -f docker-compose.dev.stacks-blockchain.yml -f docker-compose.dev.bitcoind.yml logs -t -f",
"docs:generate": "cd docs && npm run generate:types && npm run generate:docs && cd ../client && typedoc",
"docs:generate": "cd docs && npm run generate:types && npm run generate:docs && cd ../client && npm run generate:docs",
"docs:deploy": "npm run docs:generate && cd docs && gulp deployDocs"
},
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions src/api/controllers/db-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ export async function getBlockFromDataStore(
parent_block_hash: dbBlock.parent_block_hash,
burn_block_time: dbBlock.burn_block_time,
burn_block_time_iso: unixEpochToIso(dbBlock.burn_block_time),
burn_block_hash: dbBlock.burn_block_hash,
burn_block_height: dbBlock.burn_block_height,
miner_txid: dbBlock.miner_txid,
txs: txIds.results,
};
return { found: true, result: apiBlock };
Expand Down
3 changes: 3 additions & 0 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { getTxSenderAddress } from '../event-stream/reader';
export interface DbBlock {
block_hash: string;
burn_block_time: number;
burn_block_hash: string;
burn_block_height: number;
miner_txid: string;
index_block_hash: string;
parent_index_block_hash: string;
parent_block_hash: string;
Expand Down
17 changes: 14 additions & 3 deletions src/datastore/postgres-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ const MEMPOOL_TX_ID_COLUMNS = `
`;

const BLOCK_COLUMNS = `
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height, burn_block_time, canonical
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height,
burn_block_time, burn_block_hash, burn_block_height, miner_txid, canonical
`;

interface BlockQueryResult {
Expand All @@ -162,6 +163,9 @@ interface BlockQueryResult {
parent_microblock: Buffer;
block_height: number;
burn_block_time: number;
burn_block_hash: Buffer;
burn_block_height: number;
miner_txid: Buffer;
canonical: boolean;
}

Expand Down Expand Up @@ -787,8 +791,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
const result = await client.query(
`
INSERT INTO blocks(
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height, burn_block_time, canonical
) values($1, $2, $3, $4, $5, $6, $7, $8)
block_hash, index_block_hash, parent_index_block_hash, parent_block_hash, parent_microblock, block_height,
burn_block_time, burn_block_hash, burn_block_height, miner_txid, canonical
) values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)
ON CONFLICT (index_block_hash)
DO NOTHING
`,
Expand All @@ -800,6 +805,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
hexToBuffer(block.parent_microblock),
block.block_height,
block.burn_block_time,
hexToBuffer(block.burn_block_hash),
block.burn_block_height,
hexToBuffer(block.miner_txid),
block.canonical,
]
);
Expand All @@ -815,6 +823,9 @@ export class PgDataStore extends (EventEmitter as { new (): DataStoreEventEmitte
parent_microblock: bufferToHexPrefixString(row.parent_microblock),
block_height: row.block_height,
burn_block_time: row.burn_block_time,
burn_block_hash: bufferToHexPrefixString(row.burn_block_hash),
burn_block_height: row.burn_block_height,
miner_txid: bufferToHexPrefixString(row.miner_txid),
canonical: row.canonical,
};
return block;
Expand Down
3 changes: 3 additions & 0 deletions src/event-stream/core-node-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export interface CoreNodeMessage {
block_hash: string;
block_height: number;
burn_block_time: number;
burn_block_hash: string;
burn_block_height: number;
miner_txid: string;
index_block_hash: string;
parent_index_block_hash: string;
parent_block_hash: string;
Expand Down
3 changes: 3 additions & 0 deletions src/event-stream/event-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ async function handleClientMessage(msg: CoreNodeMessage, db: DataStore): Promise
parent_microblock: parsedMsg.parent_microblock,
block_height: parsedMsg.block_height,
burn_block_time: parsedMsg.burn_block_time,
burn_block_hash: parsedMsg.burn_block_hash,
burn_block_height: parsedMsg.burn_block_height,
miner_txid: parsedMsg.miner_txid,
};

logger.verbose(
Expand Down
12 changes: 12 additions & 0 deletions src/migrations/1584604583726_blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
type: 'integer',
notNull: true,
},
burn_block_hash: {
type: 'bytea',
notNull: true,
},
burn_block_height: {
type: 'integer',
notNull: true,
},
miner_txid: {
type: 'bytea',
notNull: true,
},
parent_index_block_hash: {
type: 'bytea',
notNull: true,
Expand Down
12 changes: 12 additions & 0 deletions src/tests/api-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ describe('api tests', () => {
parent_microblock: '0x9876',
block_height: 1235,
burn_block_time: 94869286,
burn_block_hash: '0x1234',
burn_block_height: 123,
miner_txid: '0x4321',
canonical: true,
};
await db.updateBlock(client, block);
Expand Down Expand Up @@ -1198,6 +1201,9 @@ describe('api tests', () => {
parent_microblock: '0x9876',
block_height: 1,
burn_block_time: 1594647996,
burn_block_hash: '0x1234',
burn_block_height: 123,
miner_txid: '0x4321',
canonical: true,
};
const tx1: DbTx = {
Expand Down Expand Up @@ -1309,6 +1315,9 @@ describe('api tests', () => {
parent_microblock: '0x9876',
block_height: 1235,
burn_block_time: 1594647996,
burn_block_hash: '0x1234',
burn_block_height: 123,
miner_txid: '0x4321',
canonical: true,
};
await db.updateBlock(client, block);
Expand Down Expand Up @@ -1341,6 +1350,9 @@ describe('api tests', () => {
const expectedResp = {
burn_block_time: 1594647996,
burn_block_time_iso: '2020-07-13T13:46:36.000Z',
burn_block_hash: '0x1234',
burn_block_height: 123,
miner_txid: '0x4321',
canonical: true,
hash: '0x1234',
height: 1235,
Expand Down
Loading

0 comments on commit 9e9fd99

Please sign in to comment.