From fc1284b37435141c44fc449a9793a97a43a39687 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Mon, 7 Aug 2017 22:09:56 -0400 Subject: [PATCH] sync mocked readme updated. --- README.md | 40 ++++++++++++++++++++++++++++------------ config/index.js | 2 +- index.js | 2 +- lib/api/status.js | 11 +++++++++-- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e006682..e7344ed 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Rebuilt Bitcore with Bcoin engine and Insight API sitting on top of Mongo. ### Requirements -Mongodo running on your system. +Mongodb running on your system. node >=7.6.0 - This requirement comes from Bcoin. Developed under 8.2.0. @@ -22,21 +22,30 @@ A configuration object exists in /config/index.js that accepts a config for Bcoi Mongo will create the bitcore db and a blocks/transactions collection automatically. These collectionss have indexes. Bcoin also syncs to the prefix set in config. To reset/start over you need to drop both collections and delete the bcoin datadir. +Bcoin offers a few database types. The most ideal for our purpose is the in memory database. Unfortunately, Bcoin will not record blockchain sync checkpoints in this mode. Every restart of the client would result in Bcoin sync'ing from the Genesis block. Long term, we should consider sending them a friendly PR. + +Alternatively, I've explored putting mongo into Bcoin. The db interface seems simple enough. Bcoin mostly get/puts but it is surprisingly complicated under the hood. + +So Bcoin creates its own leveldb. + +### Resetting Application State ``` mongo use bitcore db.blocks.drop() db.transactions.drop() +Ctrl+D out of mongo + rm -rf ~/.bcoin/chain.ldb ``` ### Nginx -The API is configured to run on port 3000 by default. Use the standard Nginx reverse proxy to flip http to https and handle ssl certs. +The API is configured to run on port 3000 by default. Use the standard Nginx reverse proxy on ports 80/443 to flip http to https and handle ssl certs. ### Priorities -1. Required Insight-UI +1. Required for Insight-UI * /addr/:addrStr/?noTxList=1 * X /block/:blockhash @@ -44,20 +53,27 @@ The API is configured to run on port 3000 by default. Use the standard Nginx rev * X /block-index/:blockHeight * X /currency * X /version -* /status -* /sync +* X /status - Stubbed. Prior status was for bitcoind +* /sync - Tricky. Bcoin gets the bestHeight from peers but does not save that information. Will show best height - currently Mocked * X /peer * X /tx/:txId -* /txs -* /txs +* /txs - Done(ish - no pagination) for most recent txs. Needs block (hash) and address * sockets -# ToDo -* Mongo Models : Bcoin primitives. A Bcoin block does not present all of bitcore's data. +# ToDo but required for a release +* API Endpoints +* Mongo Models : Bcoin primitives. A Bcoin block primitive does not represent all of bitcore's data. +1. scriptpubkey asm +2. peer's best block height is learned on peer connect but not retained by the app. Block height is the current sync height + +# ToDo but not Required for a release * Reorg testing - Bcoin will handle this but we need to account for this in our mongo indexes. * JSDoc & Unit tests * Rate Limiting -* Helmet -* Rate Limiting -* Sanitize user input - mongo and api params. Just make a quick middleware \ No newline at end of file +* Helmet for security +* Caching +* Sanitize user input - mongo and api params. Just make a quick middleware. +* Change Mongo subdocuments into .populate Object Id relationships. This will reduce size & increase performance +* Make the current api the 'legacy' api and setup a real api with uniform verbage/params +* Remove hh:mm:ss from log file names and append to same file for the same day \ No newline at end of file diff --git a/config/index.js b/config/index.js index d4e3946..41ee29a 100644 --- a/config/index.js +++ b/config/index.js @@ -1,5 +1,5 @@ const config = { - full_node: true, + start_node: true, logging: 'debug', bcoin: { network: 'main', diff --git a/index.js b/index.js index 74e7e3a..47b2141 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ logger.log('debug', db.connect(config.mongodb.uri, config.mongodb.options); db.connection.once('open', () => { - if (config.full_node) Bcoin.start(); + if (config.start_node) Bcoin.start(); Api.listen(config.api.port, () => { logger.log('debug', diff --git a/lib/api/status.js b/lib/api/status.js index 205c940..559ea8b 100644 --- a/lib/api/status.js +++ b/lib/api/status.js @@ -13,14 +13,21 @@ module.exports = function statusAPI(router) { difficulty: 0, testnet: false, relayfee: 0, - errors: "", + errors: '', network: 'main', }, }); }); router.get('/sync', (req, res) => { - res.send('sync'); + res.json({ + status: '', + blockChainHeight: 0, + syncPercentage: 0, + height: 0, + error: null, + type: 'bitcore node', + }); }); router.get('/peer', (req, res) => {