diff --git a/lib/cli/flocore.js b/lib/cli/flocore.js index 37e47e49..56a3f422 100644 --- a/lib/cli/flocore.js +++ b/lib/cli/flocore.js @@ -33,7 +33,9 @@ function main(parentServicesPath, additionalServices) { // Gracefully Shut Down process.on('SIGTERM', function () { + console.log("Shutting down flocore-node") node.stop(function() { + console.log("flocore-node successfully stopped!") process.exit(0) }) }) diff --git a/lib/scaffold/start.js b/lib/scaffold/start.js index a6dd00a5..b008be09 100644 --- a/lib/scaffold/start.js +++ b/lib/scaffold/start.js @@ -201,12 +201,13 @@ function cleanShutdown(_process, node) { return _process.exit(1); } log.info('Halted'); - _process.exit(0); + process.exit(0); }); } function exitHandler(options, _process, node, err) { - if (err) { + // Handle and log errors other than SIGINT shutdown + if (err && err !== "SIGINT") { log.error('uncaught exception:', err); if(err.stack) { log.error(err.stack); @@ -218,6 +219,7 @@ function exitHandler(options, _process, node, err) { _process.exit(-1); }); } + // Handle SIGINT (Ctrl+C) if (options.sigint) { if (!shuttingDown) { shuttingDown = true; diff --git a/lib/services/p2p/bcoin.js b/lib/services/p2p/bcoin.js index 65a60411..8580ba4d 100644 --- a/lib/services/p2p/bcoin.js +++ b/lib/services/p2p/bcoin.js @@ -3,64 +3,50 @@ var index = require('../../'); var log = index.log; var bcoin = require('fcoin'); -var bzmq = require('bzmq'); +// var bzmq = require('bzmq'); var Bcoin = function(options) { this._config = this._getConfig(options); }; Bcoin.prototype.start = function(callback) { - var self = this; - self._bcoin = new bcoin.FullNode(self._config); - - //bcoin.set(self._config.network || 'main') - //const walletPlugin = bcoin.wallet.plugin; - - // Make fcoin add the wallet plugin - //self._bcoin.use(walletPlugin) - // bzmq allows zmq connections to fcoin - //self._bcoin.use(bzmq) - //self._bzmq = self._bcoin.require('zmq') + this._bcoin = new bcoin.FullNode(this._config); log.info('Starting fcoin FullNode...'); - self._bcoin.open().then(function() { - - // Startup the wallet plugin - //self._walletdb = self._bcoin.require('walletdb'); - // self._walletdb.open().then(function() { - - // Continue bcoin startup - self._bcoin.connect().then(function() { - log.info('Waiting for Fcoin to sync'); - self._bcoin.startSync(); - // this will instruct the p2p service to start trying to connect to bcoin right away - callback(); - }); - - // }) + this._bcoin.open().then(() => { + this._bcoin.connect().then(() => { + this._bcoin.startSync(); + callback(); + }); }); }; -Bcoin.prototype.stop = function() { - this._bcoin.stopSync(); - this._bcoin.disconnect(); - this._bcoin.close(); +Bcoin.prototype.stop = function(callback) { + this._bcoin.close().then(() => { + log.info("fcoin shutdown") + callback() + }); }; // --- privates Bcoin.prototype._getConfig = function(options) { var config = { - checkpoints: true, network: options.network || 'main', - listen: true, + port: options.port, + + logFile: true, logConsole: true, logLevel: 'info', - port: options.port, - 'persistent-mempool': true, + + indexTx: true, + indexAddress: true, + + checkpoints: true, + memory: false, workers: true, - config: true + listen: true }; if (options.prefix) { config.prefix = options.prefix; diff --git a/lib/services/p2p/index.js b/lib/services/p2p/index.js index a2296fbd..e1620c1e 100644 --- a/lib/services/p2p/index.js +++ b/lib/services/p2p/index.js @@ -432,9 +432,6 @@ P2P.prototype._setResourceFilter = function(filter) { }; P2P.prototype._startBcoin = function(callback) { - - var self = this; - var network; var port; if (['livenet', 'live', 'main', 'mainnet'].indexOf(this.node.network) !== -1) { @@ -448,13 +445,13 @@ P2P.prototype._startBcoin = function(callback) { port = this._configPeers[0].port || 48444; } - self._bcoin = new Bcoin({ + this._bcoin = new Bcoin({ network: network, - prefix: self.node.datadir, + prefix: this.node.datadir, port: port }); - self._bcoin.start(callback); + this._bcoin.start(callback); }; diff --git a/package.json b/package.json index ea2acdd6..79d5fde9 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "bitcoind-rpc": "^0.7.2", "bn.js": "^4.11.8", "body-parser": "^1.13.3", - "bzmq": "^0.1.2", "colors": "^1.1.2", "commander": "^2.8.1", "errno": "^0.1.4",