http/rpc: mining. logs and error handling.

This commit is contained in:
Christopher Jeffrey 2016-12-13 20:21:12 -08:00
parent ca9fc63309
commit eef018004f
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 25 additions and 9 deletions

View File

@ -63,6 +63,16 @@ HTTPBase.prototype._init = function _init() {
this.server.on('connection', function(socket) {
socket.on('error', function(err) {
var str;
if (err.message === 'Parse Error') {
str = 'http_parser.execute failure (';
str += 'parsed=' + (err.bytesParsed || -1);
str += ' code=' + err.code;
str += ')';
err = new Error(str);
}
self.emit('error', err);
try {

View File

@ -1465,7 +1465,7 @@ RPC.prototype.__submitblock = co(function* submitblock(block) {
RPC.prototype.getblocktemplate = co(function* getblocktemplate(args) {
var mode = 'template';
var version = -1;
var coinbase = true;
var coinbase = false;
var i, opt, lpid, rules, cap, block;
var coinbasevalue, coinbasetxn;
@ -1510,11 +1510,13 @@ RPC.prototype.getblocktemplate = co(function* getblocktemplate(args) {
case 'coinbasevalue':
coinbasevalue = true;
break;
case 'coinbase/append':
break;
}
}
if (!coinbasetxn)
coinbase = false;
if (coinbasetxn)
coinbase = true;
}
}
@ -1629,6 +1631,7 @@ RPC.prototype.__template = co(function* _template(version, coinbase, rules) {
mintime: block.ts,
maxtime: this.network.now() + 2 * 60 * 60,
mutable: mutable,
expires: 0xffffffff,
noncerange: '00000000ffffffff',
sigoplimit: constants.block.MAX_SIGOPS_COST / scale | 0,
sizelimit: constants.block.MAX_RAW_SIZE,

View File

@ -102,11 +102,11 @@ HTTPServer.prototype._init = function _init() {
var self = this;
this.server.on('request', function(req, res) {
if (req.pathname === '/')
return;
// if (req.pathname === '/')
// return;
self.logger.debug('Request for path=%s (%s).',
req.pathname, req.socket.remoteAddress);
self.logger.debug('Request for method=%s path=%s (%s).',
req.method, req.pathname, req.socket.remoteAddress);
});
this.server.on('listening', function(address) {
@ -204,6 +204,8 @@ HTTPServer.prototype._init = function _init() {
if (req.method === 'POST' && req.pathname === '/') {
enforce(typeof req.body.method === 'string', 'Method must be a string.');
if (!req.body.params)
req.body.params = [];
enforce(Array.isArray(req.body.params), 'Params must be an array.');
req.options = {};
return next();
@ -546,14 +548,15 @@ HTTPServer.prototype._init = function _init() {
this.rpc = new RPC(this.node);
}
this.logger.debug('RPC call for %s:', req.pathname);
this.logger.debug(req.body);
if (req.body.method === 'getwork') {
res.setHeader('X-Long-Polling', '/?longpoll=1');
if (req.query.longpoll)
req.body.method = 'getworklp';
}
this.logger.info(req.body);
try {
json = yield this.rpc.execute(req.body);
} catch (err) {