osagga / bitcore-node-cash

Extensible full node using Bitcore
https://bitcore.io/
Other
9 stars 2 forks source link

Can't index block 0 #1

Open osagga opened 6 years ago

osagga commented 6 years ago

Accessing block 0 (the Gensis block) by its hash raises a 'block not in index' as follows:

[2018-06-22T02:25:14.630Z] error: Error: block not in index
    at bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at bitcore-node/lib/services/block/index.js:471:14
    at bitcore-node/lib/services/db/index.js:107:16
    at bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T02:25:14.631Z] info: ::1 "GET /api/block/000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" 503 18 0.882 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) 

Also passing '0' into the search box crashes the bitcore-node as follows:

[2018-06-22T02:28:36.223Z] error: Error: block not in index
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T02:28:36.224Z] info: ::1 "GET /api/block/0" 503 18 0.695 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36" 
[2018-06-22T02:28:36.224Z] error: Error: block not in index
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T02:28:36.224Z] error: uncaught exception: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at validateHeader (_http_outgoing.js:503:11)
    at ServerResponse.setHeader (_http_outgoing.js:510:3)
    at ServerResponse.header (/bitcore-node/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/bitcore-node/node_modules/express/lib/response.js:170:12)
    at Common.handleErrors (/bitcore-node/node_modules/insight-api/lib/common.js:22:23)
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:28
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T02:28:36.225Z] error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at validateHeader (_http_outgoing.js:503:11)
    at ServerResponse.setHeader (_http_outgoing.js:510:3)
    at ServerResponse.header (/bitcore-node/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/bitcore-node/node_modules/express/lib/response.js:170:12)
    at Common.handleErrors (/bitcore-node/node_modules/insight-api/lib/common.js:22:23)
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:28
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T02:28:36.225Z] info: Beginning shutdown
[2018-06-22T02:28:36.225Z] info: P2P Service: disconnecting pool and peers. SIGINT issued, system shutdown initiated
[2018-06-22T02:28:36.225Z] info: Disconnected from peer: 127.0.0.1
[2018-06-22T02:28:36.225Z] warn: Node is stopping, gently closing the database. Please wait, this could take a while.
[2018-06-22T02:28:36.225Z] info: Stopping insight-ui
[2018-06-22T02:28:36.225Z] info: Stopping insight-api
[2018-06-22T02:28:36.226Z] info: Stopping web
[2018-06-22T02:28:36.226Z] info: Stopping fee
[2018-06-22T02:28:36.226Z] info: Stopping address
[2018-06-22T02:28:36.226Z] info: Stopping transaction
[2018-06-22T02:28:36.226Z] info: Stopping block
[2018-06-22T02:28:36.226Z] info: Stopping mempool
[2018-06-22T02:28:36.226Z] info: Stopping timestamp
[2018-06-22T02:28:36.226Z] info: Stopping header
[2018-06-22T02:28:36.226Z] info: Stopping db
[2018-06-22T02:28:36.303Z] error: Error: Shutdown sequence underway, not able to complete the query
    at DB.get (/bitcore-node/lib/services/db/index.js:120:8)
    at TransactionService._getTransaction (/bitcore-node/lib/services/transaction/index.js:255:12)
    at nextTask (/bitcore-node/node_modules/async/dist/async.js:5324:14)
    at Object.waterfall (/bitcore-node/node_modules/async/dist/async.js:5334:5)
    at TransactionService.getTransaction (/bitcore-node/lib/services/transaction/index.js:125:9)
    at TransactionService.getDetailedTransaction (/bitcore-node/lib/services/transaction/index.js:56:8)
    at TxController.transaction (/bitcore-node/node_modules/insight-api/lib/transactions.js:40:21)
    at paramCallback (/bitcore-node/node_modules/express/lib/router/index.js:404:7)
    at param (/bitcore-node/node_modules/express/lib/router/index.js:384:5)
    at Function.process_params (/bitcore-node/node_modules/express/lib/router/index.js:410:3)
[2018-06-22T02:28:36.303Z] info: ::1 "GET /api/tx/0" 503 58 1.182 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36" 
[addresses.js.130] 0
[2018-06-22T02:28:36.352Z] info: ::1 "GET /api/addr/0/?noTxList=1" 400 26 1.054 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36" 
[2018-06-22T02:28:36.355Z] error: Error: Shutdown sequence underway, not able to complete the query
    at DB.get (/bitcore-node/lib/services/db/index.js:120:8)
    at HeaderService._getHeader (/bitcore-node/lib/services/header/index.js:610:12)
    at HeaderService.getBlockHeader (/bitcore-node/lib/services/header/index.js:117:17)
    at BlockController.blockIndex (/bitcore-node/node_modules/insight-api/lib/blocks.js:184:16)
    at paramCallback (/bitcore-node/node_modules/express/lib/router/index.js:404:7)
    at param (/bitcore-node/node_modules/express/lib/router/index.js:384:5)
    at Function.process_params (/bitcore-node/node_modules/express/lib/router/index.js:410:3)
    at next (/bitcore-node/node_modules/express/lib/router/index.js:275:10)
    at /bitcore-node/node_modules/insight-api/lib/index.js:204:7
    at Layer.handle [as handle_request] (/bitcore-node/node_modules/express/lib/router/layer.js:95:5)
[2018-06-22T02:28:36.355Z] info: ::1 "GET /api/block-index/0" 503 58 0.462 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36" 
[2018-06-22T02:28:36.421Z] info: Stopping p2p

It's probably a problem in the source code regrading handling the first block. I'll keep looking into it.

osagga commented 6 years ago
[2018-06-22T03:52:14.175Z] error: Error: block not in index
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T03:52:14.175Z] error: uncaught exception: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at validateHeader (_http_outgoing.js:503:11)
    at ServerResponse.setHeader (_http_outgoing.js:510:3)
    at ServerResponse.header (/bitcore-node/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/bitcore-node/node_modules/express/lib/response.js:170:12)
    at Common.handleErrors (/bitcore-node/node_modules/insight-api/lib/common.js:22:23)
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:28
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14

It seems that the node crashes because two Errors (Error [ERR_HTTP_HEADERS_SENT] and Error: block not in index) are raised at the same time, because when each error is raised individually, the node doesn't crash.

Update: this problem seems to happen when I look for any block index that is not in the database. When I try to look for an index 2010 (that's not in the blockchain):

[2018-06-22T04:07:28.170Z] error: Error: block not in index
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at /bitcore-node/lib/services/block/index.js:123:14
    at /bitcore-node/lib/services/block/index.js:491:16
    at /bitcore-node/lib/services/header/index.js:617:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T04:07:28.172Z] info: ::1 "GET /api/block/2010" 503 18 2.902 "PostmanRuntime/7.1.5" 
[2018-06-22T04:07:28.172Z] error: Error: block not in index
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:41
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T04:07:28.172Z] error: uncaught exception: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at validateHeader (_http_outgoing.js:503:11)
    at ServerResponse.setHeader (_http_outgoing.js:510:3)
    at ServerResponse.header (/bitcore-node/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/bitcore-node/node_modules/express/lib/response.js:170:12)
    at Common.handleErrors (/bitcore-node/node_modules/insight-api/lib/common.js:22:23)
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:28
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T04:07:28.172Z] error: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at validateHeader (_http_outgoing.js:503:11)
    at ServerResponse.setHeader (_http_outgoing.js:510:3)
    at ServerResponse.header (/bitcore-node/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (/bitcore-node/node_modules/express/lib/response.js:170:12)
    at Common.handleErrors (/bitcore-node/node_modules/insight-api/lib/common.js:22:23)
    at /bitcore-node/node_modules/insight-api/lib/blocks.js:79:28
    at /bitcore-node/lib/services/block/index.js:471:14
    at /bitcore-node/lib/services/db/index.js:107:16
    at /bitcore-node/node_modules/levelup/lib/levelup.js:168:14
[2018-06-22T04:07:28.173Z] info: Beginning shutdown
[2018-06-22T04:07:28.173Z] info: P2P Service: disconnecting pool and peers. SIGINT issued, system shutdown initiated
[2018-06-22T04:07:28.173Z] info: Disconnected from peer: 127.0.0.1
[2018-06-22T04:07:28.173Z] warn: Node is stopping, gently closing the database. Please wait, this could take a while.
[2018-06-22T04:07:28.174Z] info: Stopping insight-ui
[2018-06-22T04:07:28.174Z] info: Stopping insight-api
[2018-06-22T04:07:28.174Z] info: Stopping web
[2018-06-22T04:07:28.174Z] info: Stopping fee
[2018-06-22T04:07:28.174Z] info: Stopping address
[2018-06-22T04:07:28.174Z] info: Stopping transaction
[2018-06-22T04:07:28.174Z] info: Stopping block
[2018-06-22T04:07:28.174Z] info: Stopping mempool
[2018-06-22T04:07:28.174Z] info: Stopping timestamp
[2018-06-22T04:07:28.175Z] info: Stopping header
[2018-06-22T04:07:28.175Z] info: Stopping db
[2018-06-22T04:07:28.175Z] info: Stopping p2p