Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
cmgustavo committed Feb 19, 2014
2 parents afe5c24 + d8092e4 commit 0f7ad7b
Show file tree
Hide file tree
Showing 27 changed files with 519 additions and 495 deletions.
15 changes: 12 additions & 3 deletions app/controllers/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ exports.block = function(req, res, next, hash) {
if (err || !block)
return common.handleErrors(err, res, next);
else {
req.block = block.info;
return next();
bdb.getPoolInfo(block.info.tx[0], function(info) {
block.info.poolInfo = info;
req.block = block.info;
return next();
});
}
});
};
Expand Down Expand Up @@ -63,7 +66,12 @@ var getBlock = function(blockhash, cb) {
isOrphan: 1,
};
}
return cb(err, block.info);

bdb.getPoolInfo(block.info.tx[0], function(info) {
block.info.poolInfo = info;
return cb(err, block.info);
});

});
};

Expand Down Expand Up @@ -127,6 +135,7 @@ exports.list = function(req, res) {
hash: b.hash,
time: b.ts || info.time,
txlength: info.tx.length,
poolInfo: info.poolInfo
});
});
}, function(err, allblocks) {
Expand Down
13 changes: 9 additions & 4 deletions app/controllers/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ module.exports.init = function(app, io_ext) {

module.exports.broadcastTx = function(tx) {
if (ios) {
var t = {};
var t;
if (typeof tx === 'string') {
t = {
txid: tx
};
} else {
t = tx;
}

else {
t = {
txid: tx.txid,
size: tx.size,
};
// Outputs
var valueOut = 0;
t.vout.forEach(function(o) {
tx.vout.forEach(function(o) {
valueOut += o.value * util.COIN;
});

Expand Down
21 changes: 14 additions & 7 deletions app/models/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,27 @@ function spec() {
var db = new TransactionDb();
async.series([
function (cb) {
var seen={};
db.fromAddr(self.addrStr, function(err,txOut){
if (err) return cb(err);
txOut.forEach(function(txItem){

var add=0, addSpend=0;
var v = txItem.value_sat;

txs.push({txid: txItem.txid, ts: txItem.ts});
if ( !seen[txItem.txid] ) {
txs.push({txid: txItem.txid, ts: txItem.ts});
seen[txItem.txid]=1;
add=1;
}

if (txItem.spentTxId) {
if (txItem.spentTxId && !seen[txItem.spentTxId] ) {
txs.push({txid: txItem.spentTxId, ts: txItem.spentTs});
seen[txItem.spentTxId]=1;
addSpend=1;
}

if (txItem.isConfirmed) {
self.txApperances += 1;
self.txApperances += add;
self.totalReceivedSat += v;
if (! txItem.spentTxId ) {
//unspent
Expand All @@ -100,17 +107,17 @@ function spec() {
// unspent
self.balanceSat += v;
self.unconfirmedBalanceSat -= v;
self.unconfirmedTxApperances += 1;
self.unconfirmedTxApperances += addSpend;
}
else {
// spent
self.totalSentSat += v;
self.txApperances += 1;
self.txApperances += addSpend;
}
}
else {
self.unconfirmedBalanceSat += v;
self.unconfirmedTxApperances += 1;
self.unconfirmedTxApperances += add;
}
});
return cb();
Expand Down
56 changes: 56 additions & 0 deletions dev-util/stats
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@


first 5%

=> with data + mongo + w/RPC for blocks: 48.8s
=> with RPC + mongo: 2m26s
=> with files + mongo + wo/RPC for blocks: 36.7s
=> with files + mongo + wo/RPC for blocks + wo/mongoIndexes:


first 10%

=> sin RPC, sin Tx, sin store block => 0.7s
=> sin RPC, sin grabar, procesando TX => 8.5s
=> sin RPC, sin TX processing, sin grabar => 12s28
=> con RPC, TX processing, sin Grabar Tx, grabando bloques => 29s
=> con RPC, sin TX processing, sin Grabar Tx, grabando bloques => 35s
=> con RPC, TX processing, sin Grabar Tx, grabando bloques => 43s

=> TX processing, sin RPC, sin saves TX, y blocks => 11.6s
=> TX processing, CON RPC, sin saves TX, y blocks => 35s
=> con RPC, TX processing, sin saves TX => 45s
=> con RPC, TX processing, Grabarndo todo => 78s
=> con RPC, TX processing, Grabarndo todo => 78s
(18k blocks, 36k txouts)

//LEVEL DB
=> sin RPC, TX processing, todo en level => 14s
=> con RPC, TX processing, todo en level => 39.7s
=> con RPC, TX processing, tx mongo, blocks en level => 64s


=> sin RPC, TX processing, todo en level, handling REORGs, more data => 28s
=> sin RPC, TX processing, todo en level, handling REORGs, more data, tx ts => 34t s


//FROM blk00002.dat (more txs), 5%

=> now total : 1m13s
=> removing block writes => 1m8s
=> sacando los contenidos adentro de getblock from file de => 4.5s!!

=> con base58 cpp => 21s
=> toda la testnet => 17m

10% de blk2
=> 50s con base58cpp
=> 41s commentando todo addr
=> 5s commentando todo get HistoricSync.prototype.getBlockFromFile = function(cb) {
=> 15s commentando todo get HistoricSync.prototype.getBlockFromFile = function(cb) {

10% de blk 1
=> 59s
=> 15s comentando desde b.getStandardizedObject()
=> 39s comentando dps b.getStandardizedObject()

37 changes: 10 additions & 27 deletions insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,31 @@ walk(models_path);
* p2pSync process
*/

var peerSync = new PeerSync();
var peerSync = new PeerSync({shouldBroadcast: true});

if (!config.disableP2pSync) {
var ps = peerSync;
ps.init({
shouldBroadcast: true,
}, function() {
ps.run();
});
peerSync.run();
}

/**
* historic_sync process
*/
var historicSync = {};
var historicSync = new HistoricSync({
shouldBroadcastSync: true
});
peerSync.historicSync = historicSync;

if (!config.disableHistoricSync) {
historicSync = new HistoricSync();

historicSync.init({
shouldBroadcastSync: true,
}, function(err) {
historicSync.start({}, function(err){
if (err) {
var txt = 'ABORTED with error: ' + err.message;
console.log('[historic_sync] ' + txt);
}
else {
historicSync.smartImport({}, function(err){
var txt = 'ended.';
if (err)
txt = 'ABORTED with error: ' + err.message;
else if (ps) {
ps.allowReorgs = true;
ps.historicSync = historicSync;
}

console.log('[historic_sync] ' + txt, historicSync.info());
});
}
if (peerSync) peerSync.allowReorgs = true;
});
}

else
if (peerSync) peerSync.allowReorgs = true;


//express settings
Expand Down
23 changes: 20 additions & 3 deletions lib/BlockDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ function spec(b) {
var Rpc = b.rpc || require('./Rpc').class();
var PoolMatch = b.poolMatch || require('./PoolMatch').class(config);

var buffertools = require('buffertools');
var TransactionDb = require('./TransactionDb.js').class();

var BlockDb = function() {
BlockDb.super(this, arguments);
this.poolMatch = new PoolMatch();
Expand Down Expand Up @@ -57,7 +60,7 @@ function spec(b) {
return db.batch()
.put(time_key, b.hash)
.put(MAIN_PREFIX + b.hash, 1)
.put(PREV_PREFIX + b.hash, b.previousblockhash)
.put(PREV_PREFIX + b.hash, b.previousblockhash)
.write(function(err){
if (!err) {
self.emit('new_block', {blockid: b.hash});
Expand Down Expand Up @@ -136,7 +139,7 @@ function spec(b) {
});
};

BlockDb.prototype.countNotOrphan = function(cb) {
BlockDb.prototype.countConnected = function(cb) {
var c = 0;
console.log('Counting connected blocks. This could take some minutes');
db.createReadStream({start: MAIN_PREFIX, end: MAIN_PREFIX + '~' })
Expand Down Expand Up @@ -164,6 +167,21 @@ function spec(b) {
});
};

BlockDb.prototype.getPoolInfo = function(tx, cb) {
var tr = new TransactionDb();
var self = this;

tr._getInfo(tx, function(e, a) {
if (e) return cb(false);

if (a.isCoinBase) {
var coinbaseHexBuffer = new Buffer(a.vin[0].coinbase, 'hex');
var a = self.poolMatch.match(coinbaseHexBuffer);

return cb(a);
}
});
};

BlockDb.prototype.fromHashWithInfo = function(hash, cb) {
var self = this;
Expand All @@ -175,7 +193,6 @@ function spec(b) {
if (err) return cb(err);

info.isMainChain = val ? true : false;
// info.poolInfo = self.poolMatch.match(info.hex);

return cb(null, {
hash: hash,
Expand Down
Loading

0 comments on commit 0f7ad7b

Please sign in to comment.