From 4d23191116830b6a50af230e5a4320e9128d9944 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 18 Jan 2014 18:28:24 -0300 Subject: [PATCH 1/4] better smart syncs --- app/models/Block.js | 1 + app/models/Transaction.js | 4 +- lib/HistoricSync.js | 110 +++++++++++++++++++++++++++----------- lib/Sync.js | 76 ++++++++++++++------------ server.js | 7 ++- util/sync.js | 11 ++-- 6 files changed, 132 insertions(+), 77 deletions(-) diff --git a/app/models/Block.js b/app/models/Block.js index 709fbcf..e4d84d3 100644 --- a/app/models/Block.js +++ b/app/models/Block.js @@ -27,6 +27,7 @@ var BlockSchema = new Schema({ }, time: Number, nextBlockHash: String, + isOrphan: Boolean, }); /** diff --git a/app/models/Transaction.js b/app/models/Transaction.js index 84c8614..fdad11e 100644 --- a/app/models/Transaction.js +++ b/app/models/Transaction.js @@ -142,7 +142,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) { } else { if ( !i.coinbase ) { - console.log ('TX: %s,%d could not parse INPUT', txid, i.n); + console.log ('WARN in TX: %s: could not parse INPUT %d', txid, i.n); } return next_in(); } @@ -165,7 +165,7 @@ TransactionSchema.statics.explodeTransactionItems = function(txid, time, cb) { }, next_out); } else { - console.log ('TX: %s,%d could not parse OUTPUT', txid, o.n); + console.log ('WARN in TX: %s could not parse OUTPUT %d', txid, o.n); return next_out(); } }, diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index fdadfcc..fd64c67 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -13,14 +13,16 @@ function spec() { var Sync = require('./Sync').class(); function HistoricSync(opts) { - this.block_count= 0; - this.block_total= 0; this.network = config.network === 'testnet' ? networks.testnet: networks.livenet; var genesisHashReversed = new Buffer(32); this.network.genesisBlock.hash.copy(genesisHashReversed); this.genesis = genesisHashReversed.reverse().toString('hex'); this.sync = new Sync(opts); + + //available status: new / syncing / finished / aborted + this.status = 'new'; + this.syncInfo = {}; } function p() { @@ -32,8 +34,9 @@ function spec() { console.log.apply(this, args); } - var progress_bar = function(string, current, total) { - p(util.format('%s %d/%d [%d%%]', string, current, total, parseInt(100 * current / total))); + var printProgress = function(i) { + var per = parseInt(100 * i.syncedBlocks / i.blocksToSync); + p(util.format('status: %d/%d [%d%%]', i.syncedBlocks, i.blocksToSync, per)); }; HistoricSync.prototype.init = function(opts,cb) { @@ -47,7 +50,6 @@ function spec() { }; HistoricSync.prototype.getPrevNextBlock = function(blockHash, blockEnd, opts, cb) { - var self = this; // recursion end. @@ -71,8 +73,11 @@ function spec() { }, //show some (inacurate) status function(c) { - if (self.block_count % 1000 === 1) { - progress_bar('sync status:', self.block_count, self.block_total); + var step = parseInt(self.syncInfo.blocksToSync / 100); + if (step < 10) step = 10; + + if (self.syncInfo.syncedBlocks % step === 1) { + printProgress(self.syncInfo); } return c(); }, @@ -113,15 +118,30 @@ function spec() { ], function (err){ - if (err) - p('ERROR: @%s: %s [count: block_count: %d]', blockHash, err, self.block_count); + if (err) { + self.err = util.format('ERROR: @%s: %s [count: syncedBlocks: %d]', blockHash, err, self.syncInfo.syncedBlocks); + self.status = 'aborted'; + p(self.err); + } - if (opts.uptoexisting && existed) { - p('DONE. Found existing block: ', blockHash); - return cb(err); + else { + self.err = null; + self.status = 'syncing'; + } + + if (opts.uptoexisting && existed ) { + if (self.syncInfo.blocksToSync <= self.syncInfo.syncedBlocks) { + self.status = 'finished'; + p('DONE. Found existing block: ', blockHash); + return cb(err); + } + else { + p('WARN found target block\n\tbut blockChain Height is still higher that ours. Previous light sync must be interrupted.\n\tWill keep syncing.', self.syncInfo.syncedBlocks); + } } if (blockEnd && blockEnd === blockHash) { + self.status = 'finished'; p('DONE. Found END block: ', blockHash); return cb(err); } @@ -129,7 +149,7 @@ function spec() { // Continue if (blockInfo && blockInfo.result) { - self.block_count++; + self.syncInfo.syncedBlocks++; if (opts.prev && blockInfo.result.previousblockhash) { return self.getPrevNextBlock(blockInfo.result.previousblockhash, blockEnd, opts, cb); } @@ -144,11 +164,10 @@ function spec() { HistoricSync.prototype.import_history = function(opts, next) { var self = this; - var retry_attemps = 100; var retry_secs = 2; - var block_best; - var block_height; + var bestBlock; + var blockChainHeight; async.series([ function(cb) { @@ -175,41 +194,56 @@ function spec() { return cb(); } }, - function(cb) { - self.rpc.getInfo(function(err, res) { - if (err) return cb(err); - self.block_total = res.result.blocks; - return cb(); - }); - }, // We are not using getBestBlockHash, because is not available in all clients function(cb) { if (!opts.reverse) return cb(); self.rpc.getBlockCount(function(err, res) { if (err) return cb(err); - block_height = res.result; + blockChainHeight = res.result; return cb(); }); }, function(cb) { if (!opts.reverse) return cb(); - self.rpc.getBlockHash(block_height, function(err, res) { + self.rpc.getBlockHash(blockChainHeight, function(err, res) { if (err) return cb(err); - block_best = res.result; + bestBlock = res.result; + return cb(); }); }, + function(cb) { + // This is only to inform progress. + if (!opts.uptoexisting) { + self.rpc.getInfo(function(err, res) { + if (err) return cb(err); + self.syncInfo.blocksToSync = res.result.blocks; + return cb(); + }); + } + else { + // should be isOrphan = true or null to be more accurate. + Block.count({ isOrphan: null}, function(err, count) { + if (err) return cb(err); + + self.syncInfo.blocksToSync = blockChainHeight - count; + if (self.syncInfo.blocksToSync < 1) self.syncInfo.blocksToSync = 1; + return cb(); + }); + } + }, ], function(err) { + var start, end; function sync() { if (opts.reverse) { - start = block_best; + start = bestBlock; end = self.genesis; opts.prev = true; } @@ -219,25 +253,38 @@ function spec() { opts.next = true; } + self.syncInfo = util._extend(self.syncInfo, { + start: start, + isStartGenesis: start === self.genesis, + end: end, + isEndGenesis: end === self.genesis, + scanningForward: opts.next, + scanningBackward: opts.prev, + uptoexisting: opts.uptoexisting, + syncedBlocks: 0, + }); + p('Starting from: ', start); p(' to : ', end); p(' opts: ', JSON.stringify(opts)); self.getPrevNextBlock( start, end, opts , function(err) { - if (err && err.message.match(/ECONNREFUSED/) && retry_attemps--){ + if (err && err.message.match(/ECONNREFUSED/)){ setTimeout(function() { p('Retrying in %d secs', retry_secs); sync(); }, retry_secs * 1000); } else - return next(err, self.block_count); + return next(err); }); } + if (!err) sync(); - else + else { return next(err, 0); + } }); }; @@ -246,6 +293,7 @@ function spec() { var self = this; Block.findOne({hash:self.genesis}, function(err, b){ + if (err) return next(err); @@ -253,7 +301,7 @@ function spec() { p('Could not find Genesis block. Running FULL SYNC'); } else { - p('Genesis block found. Syncing upto know blocks.'); + p('Genesis block found. Syncing upto known blocks.'); } var opts = { diff --git a/lib/Sync.js b/lib/Sync.js index ff2ffb8..8561d4a 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -15,6 +15,48 @@ function spec() { this.tx_count = 0; } + Sync.prototype.init = function(opts, cb) { + var that = this; + + that.opts = opts; + + if (!(opts && opts.skip_db_connection)) { + + + if (!mongoose.connection.readyState == 1) { + mongoose.connect(config.db, function(err) { + if (err) { + console.log('CRITICAL ERROR: connecting to mongoDB:',err); + return (err); + } + }); + } + + that.db = mongoose.connection; + + that.db.on('error', function(err) { + console.log('MongoDB ERROR:' + err); + return cb(err); + }); + + that.db.on('disconnect', function(err) { + console.log('MongoDB disconnect:' + err); + return cb(err); + }); + + return that.db.once('open', function(err) { + return cb(err); + }); + } + else return cb(); + }; + + Sync.prototype.close = function() { + if ( this.db && this.db.readyState ) { + this.db.close(); + } + }; + Sync.prototype.storeBlock = function(block, cb) { var that = this; @@ -55,40 +97,6 @@ function spec() { return cb(err); }); }; - - - Sync.prototype.init = function(opts, cb) { - var that = this; - - that.opts = opts; - - if (!(opts && opts.skip_db_connection)) { - if (!mongoose.connection) { - mongoose.connect(config.db, {server: {auto_reconnect: true}} ); - } - - this.db = mongoose.connection; - - this.db.on('error', function(err) { - console.log('connection error:' + err); - mongoose.disconnect(); - }); - - this.db.on('disconnect', function(err) { - console.log('disconnect:' + err); - mongoose.connect(config.db, {server: {auto_reconnect: true}} ); - }); - - return that.db.once('open', cb); - } - else return cb(); - }; - - Sync.prototype.close = function() { - if (!(this.opts && this.opts.skip_db_connection)) { - this.db.close(); - } - }; return Sync; } module.defineClass(spec); diff --git a/server.js b/server.js index 84e659a..38f607f 100644 --- a/server.js +++ b/server.js @@ -50,8 +50,11 @@ if (!config.disableHistoricSync) { skip_db_connection: true, networkName: config.network }, function() { - hs.smart_import(function(){ - console.log('[historic_sync] finished!'); + hs.smart_import(function(err){ + var txt= 'ended.'; + if (err) txt = 'ABORTED with error: ' + err.message; + + console.log('[historic_sync] ' + txt, hs.syncInfo); }); }); } diff --git a/util/sync.js b/util/sync.js index beccf0f..01205d9 100755 --- a/util/sync.js +++ b/util/sync.js @@ -29,7 +29,6 @@ if (program.remove) { } */ - async.series([ function(cb) { historicSync.init(program, cb); @@ -46,18 +45,14 @@ async.series([ }, cb); } }, - function(cb) { - historicSync.close(); - return cb(); - }, ], - function(err, count) { + function(err) { + historicSync.close(); if (err) { console.log('CRITICAL ERROR: ', err); } else { - console.log('Finished. [%d blocks synced]', count[1]); + console.log('Finished.\n Status:\n', historicSync.syncInfo); } - return; }); From 08a54a40e28085d2cd5f332c55663468928befc8 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 19 Jan 2014 10:09:59 -0300 Subject: [PATCH 2/4] sync API --- .gitignore | 1 + app/controllers/status.js | 6 +++++- config/express.js | 14 ++++++++++++-- config/routes.js | 4 +++- lib/PeerSync.js | 4 ++-- lib/Sync.js | 2 +- server.js | 13 +++++++------ 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 888b5ce..aabec27 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ node_modules # extras *.swp +*.swo *~ .project peerdb.json diff --git a/app/controllers/status.js b/app/controllers/status.js index eb2f1ae..d1cd93d 100644 --- a/app/controllers/status.js +++ b/app/controllers/status.js @@ -48,10 +48,14 @@ exports.show = function(req, res, next) { res.jsonp(d); }); } - else { res.status(400).send('Bad Request'); } } }; +exports.sync = function(req, res, next) { + if (req.syncInfo) + res.jsonp(req.syncInfo); + next(); +}; diff --git a/config/express.js b/config/express.js index a25db3b..0e5c58d 100644 --- a/config/express.js +++ b/config/express.js @@ -7,7 +7,8 @@ var express = require('express'), helpers = require('view-helpers'), config = require('./config'); -module.exports = function(app, passport, db) { +module.exports = function(app, historicSync) { + app.set('showStackError', true); //Prettify HTML @@ -26,9 +27,17 @@ module.exports = function(app, passport, db) { app.set('view engine', 'jade'); //Enable jsonp - app.enable("jsonp callback"); + app.enable('jsonp callback'); + //custom middleware + function setHistoric(req, res, next) { + req.syncInfo = historicSync.syncInfo; + next(); + } + app.use('/api/sync', setHistoric); + app.configure(function() { + //cookieParser should be above session app.use(express.cookieParser()); @@ -43,6 +52,7 @@ module.exports = function(app, passport, db) { //routes should be at the last app.use(app.router); + //Setting the fav icon and static folder app.use(express.favicon()); app.use(express.static(config.root + '/public')); diff --git a/config/routes.js b/config/routes.js index 2f26dc5..fc27b78 100644 --- a/config/routes.js +++ b/config/routes.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(app) { +module.exports = function(app, historicSync) { //Home route var index = require('../app/controllers/index'); @@ -29,4 +29,6 @@ module.exports = function(app) { var st = require('../app/controllers/status'); app.get('/api/status', st.show); + app.get('/api/sync', st.sync); + }; diff --git a/lib/PeerSync.js b/lib/PeerSync.js index 49526cf..3d7e89c 100644 --- a/lib/PeerSync.js +++ b/lib/PeerSync.js @@ -15,8 +15,6 @@ function spec() { PeerSync.prototype.init = function(config, cb) { if (!config) config = {}; - var that = this; - var network = config && (config.network || 'testnet'); this.verbose = config.verbose; @@ -71,6 +69,8 @@ function spec() { } this.sync.storeTxs([tx.hash], null, function(err) { if (err) { +console.log('[PeerSync.js.71:err:]',err); //TODO + console.log('[p2p_sync] Error in handle TX: ' + JSON.stringify(err)); } }); diff --git a/lib/Sync.js b/lib/Sync.js index 8561d4a..4a4ecdc 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -23,7 +23,7 @@ function spec() { if (!(opts && opts.skip_db_connection)) { - if (!mongoose.connection.readyState == 1) { + if (mongoose.connection.readyState !== 1) { mongoose.connect(config.db, function(err) { if (err) { console.log('CRITICAL ERROR: connecting to mongoDB:',err); diff --git a/server.js b/server.js index 38f607f..59303fd 100644 --- a/server.js +++ b/server.js @@ -24,7 +24,7 @@ var express = require('express'), var config = require('./config/config'); //Bootstrap db connection -var db = mongoose.connect(config.db); +mongoose.connect(config.db); //Bootstrap models var models_path = __dirname + '/app/models'; @@ -44,17 +44,18 @@ var walk = function(path) { walk(models_path); // historic_sync process +var historicSync = {}; if (!config.disableHistoricSync) { - var hs = new HistoricSync(); - hs.init({ + historicSync = new HistoricSync(); + historicSync.init({ skip_db_connection: true, networkName: config.network }, function() { - hs.smart_import(function(err){ + historicSync.smart_import(function(err){ var txt= 'ended.'; if (err) txt = 'ABORTED with error: ' + err.message; - console.log('[historic_sync] ' + txt, hs.syncInfo); + console.log('[historic_sync] ' + txt, historicSync.syncInfo); }); }); } @@ -77,7 +78,7 @@ if (!config.disableP2pSync) { var app = express(); //express settings -require('./config/express')(app, db); +require('./config/express')(app, historicSync); //Bootstrap routes require('./config/routes')(app); From 10972fd8ddd2d629773aafb8901ac8d2130fe851 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 19 Jan 2014 12:33:39 -0300 Subject: [PATCH 3/4] sync API not emits "sync" thru socket.io --- app/controllers/socket.js | 4 +++ lib/HistoricSync.js | 56 +++++++++++++++++---------------------- lib/Sync.js | 38 ++++++++++++++++---------- server.js | 5 ++-- util/sync.js | 2 +- 5 files changed, 57 insertions(+), 48 deletions(-) diff --git a/app/controllers/socket.js b/app/controllers/socket.js index 7bcad79..fa78f55 100644 --- a/app/controllers/socket.js +++ b/app/controllers/socket.js @@ -21,3 +21,7 @@ module.exports.broadcast_tx = function(tx) { module.exports.broadcast_block = function(block) { ios.sockets.emit('block', block); }; + +module.exports.broadcastSyncInfo = function(syncInfo) { + ios.sockets.emit('block', syncInfo); +}; diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index fd64c67..2735f44 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -11,6 +11,7 @@ function spec() { var config = require('../config/config'); var Block = require('../app/models/Block'); var Sync = require('./Sync').class(); + var sockets = require('../app/controllers/socket.js'); function HistoricSync(opts) { this.network = config.network === 'testnet' ? networks.testnet: networks.livenet; @@ -20,6 +21,7 @@ function spec() { this.genesis = genesisHashReversed.reverse().toString('hex'); this.sync = new Sync(opts); + //available status: new / syncing / finished / aborted this.status = 'new'; this.syncInfo = {}; @@ -28,17 +30,14 @@ function spec() { function p() { var args = []; Array.prototype.push.apply( args, arguments ); + + args.unshift('[historic_sync]'); /*jshint validthis:true */ console.log.apply(this, args); } - var printProgress = function(i) { - var per = parseInt(100 * i.syncedBlocks / i.blocksToSync); - p(util.format('status: %d/%d [%d%%]', i.syncedBlocks, i.blocksToSync, per)); - }; - HistoricSync.prototype.init = function(opts,cb) { this.rpc = new RpcClient(config.bitcoind); this.opts = opts; @@ -49,6 +48,19 @@ function spec() { this.sync.close(); }; + + HistoricSync.prototype.showProgress = function() { + var self = this; + + var i = self.syncInfo; + var per = parseInt(100 * i.syncedBlocks / i.blocksToSync); + p(util.format('status: %d/%d [%d%%]', i.syncedBlocks, i.blocksToSync, per)); + if (self.opts.broadcast) { + sockets.broadcastSyncInfo(self.syncInfo); + } + }; + + HistoricSync.prototype.getPrevNextBlock = function(blockHash, blockEnd, opts, cb) { var self = this; @@ -77,7 +89,7 @@ function spec() { if (step < 10) step = 10; if (self.syncInfo.syncedBlocks % step === 1) { - printProgress(self.syncInfo); + self.showProgress(); } return c(); }, @@ -129,7 +141,7 @@ function spec() { self.status = 'syncing'; } - if (opts.uptoexisting && existed ) { + if (opts.upToExisting && existed ) { if (self.syncInfo.blocksToSync <= self.syncInfo.syncedBlocks) { self.status = 'finished'; p('DONE. Found existing block: ', blockHash); @@ -172,29 +184,11 @@ function spec() { async.series([ function(cb) { if (opts.destroy) { - p('Deleting Blocks...'); - self.db.collections.blocks.drop(cb); - } else { - return cb(); + p('Deleting DB...'); + return self.sync.destroy(cb); } + return cb(); }, - function(cb) { - if (opts.destroy) { - p('Deleting TXs...'); - self.db.collections.transactions.drop(cb); - } else { - return cb(); - } - }, - function(cb) { - if (opts.destroy) { - p('Deleting TXItems...'); - self.db.collections.transactionitems.drop(cb); - } else { - return cb(); - } - }, - // We are not using getBestBlockHash, because is not available in all clients function(cb) { if (!opts.reverse) return cb(); @@ -218,7 +212,7 @@ function spec() { }, function(cb) { // This is only to inform progress. - if (!opts.uptoexisting) { + if (!opts.upToExisting) { self.rpc.getInfo(function(err, res) { if (err) return cb(err); self.syncInfo.blocksToSync = res.result.blocks; @@ -260,7 +254,7 @@ function spec() { isEndGenesis: end === self.genesis, scanningForward: opts.next, scanningBackward: opts.prev, - uptoexisting: opts.uptoexisting, + upToExisting: opts.upToExisting, syncedBlocks: 0, }); @@ -306,7 +300,7 @@ function spec() { var opts = { reverse: 1, - uptoexisting: b ? true: false, + upToExisting: b ? true: false, }; return self.import_history(opts, next); diff --git a/lib/Sync.js b/lib/Sync.js index 4a4ecdc..3ff5554 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -9,6 +9,7 @@ function spec() { var Block = require('../app/models/Block'); var Transaction = require('../app/models/Transaction'); var sockets = require('../app/controllers/socket.js'); + var async = require('async'); function Sync() { @@ -16,12 +17,11 @@ function spec() { } Sync.prototype.init = function(opts, cb) { - var that = this; + var self = this; - that.opts = opts; - - if (!(opts && opts.skip_db_connection)) { + self.opts = opts; + if (!(opts && opts.skipDbConnection)) { if (mongoose.connection.readyState !== 1) { mongoose.connect(config.db, function(err) { @@ -32,19 +32,19 @@ function spec() { }); } - that.db = mongoose.connection; + self.db = mongoose.connection; - that.db.on('error', function(err) { + self.db.on('error', function(err) { console.log('MongoDB ERROR:' + err); return cb(err); }); - that.db.on('disconnect', function(err) { + self.db.on('disconnect', function(err) { console.log('MongoDB disconnect:' + err); return cb(err); }); - return that.db.once('open', function(err) { + return self.db.once('open', function(err) { return cb(err); }); } @@ -57,24 +57,34 @@ function spec() { } }; + + Sync.prototype.destroy = function(next) { + var self = this; + async.series([ + function(b) { return self.db.collections.blocks.drop(b);}, + function(b) { return self.db.collections.transactions.drop(b);}, + function(b) { return self.db.collections.transactionitems.drop(b);}, + ], next); + }; + Sync.prototype.storeBlock = function(block, cb) { - var that = this; + var self = this; Block.customCreate(block, function(err, block, inserted_txs){ if (err) return cb(err); - if (block && that.opts.broadcast_blocks) { + if (block && self.opts.broadcast_blocks) { sockets.broadcast_block(block); } - if (inserted_txs && that.opts.broadcast_txs) { + if (inserted_txs && self.opts.broadcast_txs) { inserted_txs.forEach(function(tx) { sockets.broadcast_tx(tx); }); } if (inserted_txs) - that.tx_count += inserted_txs.length; + self.tx_count += inserted_txs.length; return cb(); }); @@ -82,12 +92,12 @@ function spec() { Sync.prototype.storeTxs = function(txs, inTime, cb) { - var that = this; + var self = this; var time = inTime ? inTime : Math.round(new Date().getTime() / 1000); Transaction.createFromArray(txs, time, function(err, inserted_txs) { - if (!err && inserted_txs && that.opts.broadcast_txs) { + if (!err && inserted_txs && self.opts.broadcast_txs) { inserted_txs.forEach(function(tx) { sockets.broadcast_tx(tx); diff --git a/server.js b/server.js index 59303fd..1f49503 100644 --- a/server.js +++ b/server.js @@ -48,7 +48,8 @@ var historicSync = {}; if (!config.disableHistoricSync) { historicSync = new HistoricSync(); historicSync.init({ - skip_db_connection: true, + skipDbConnection: true, + shouldBroadcast: true, networkName: config.network }, function() { historicSync.smart_import(function(err){ @@ -65,7 +66,7 @@ if (!config.disableHistoricSync) { if (!config.disableP2pSync) { var ps = new PeerSync(); ps.init({ - skip_db_connection: true, + skipDbConnection: true, broadcast_txs: true, broadcast_blocks: true }, function() { diff --git a/util/sync.js b/util/sync.js index 01205d9..d399a1e 100755 --- a/util/sync.js +++ b/util/sync.js @@ -41,7 +41,7 @@ async.series([ historicSync.import_history({ destroy: program.destroy, reverse: program.reverse, - uptoexisting: program.uptoexisting, + upToExisting: program.uptoexisting, }, cb); } }, From 73a1d64e0187f99b0ab84a19539eeca774c2cc5c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 19 Jan 2014 12:39:34 -0300 Subject: [PATCH 4/4] README updated --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index dc344c6..8c1ed48 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,12 @@ A REST API is provided at /api. The entry points are: /api/txs/?address=ADDR /api/txs/?address=mmhmMNfBiZZ37g1tgg2t8DDbNoEdqKVxAL + +### Sync status +``` + /api/sync +``` + ## Web Socket API The web socket API is served using [socket.io](http://socket.io) at: ``` @@ -160,6 +166,22 @@ Sample output: } ``` +'sync': every 1% increment on the sync task, this event will be triggered. + +Sample output: +``` +{ +blocksToSync: 164141, +syncedBlocks: 475, +upToExisting: true, +scanningBackward: true, +isEndGenesis: true, +end: "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943", +isStartGenesis: false, +start: "000000009f929800556a8f3cfdbe57c187f2f679e351b12f7011bfc276c41b6d" +} +``` + ## Troubleshooting If you did not get all library during grunt command, please use the follow command: