db update script
This commit is contained in:
parent
c8e5b93aa3
commit
c595d49a4e
|
@ -250,6 +250,7 @@ BlockDb.prototype.setNext = function(hash, nextHash, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Unused
|
||||||
BlockDb.prototype.countConnected = function(cb) {
|
BlockDb.prototype.countConnected = function(cb) {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
console.log('Counting connected blocks. This could take some minutes');
|
console.log('Counting connected blocks. This could take some minutes');
|
||||||
|
@ -368,14 +369,10 @@ BlockDb.prototype.fillConfirmations = function(txouts, cb) {
|
||||||
return !x.spentIsConfirmedCached // not 100%cached
|
return !x.spentIsConfirmedCached // not 100%cached
|
||||||
&& !(x.isConfirmedCached && !x.spentTxId); // and not 50%cached but not spent
|
&& !(x.isConfirmedCached && !x.spentTxId); // and not 50%cached but not spent
|
||||||
});
|
});
|
||||||
//console.log('[BlockDb.js.360:txouts:]',txs.length); //TODO
|
|
||||||
var i=0;
|
|
||||||
async.eachLimit(txs, CONCURRENCY, function(txout, e_c) {
|
async.eachLimit(txs, CONCURRENCY, function(txout, e_c) {
|
||||||
if(txout.isConfirmedCached) {
|
if(txout.isConfirmedCached) {
|
||||||
//console.log('[BlockDb.js.378]', i++); //TODO
|
|
||||||
self._fillConfirmationsOneSpent(txout,height, e_c);
|
self._fillConfirmationsOneSpent(txout,height, e_c);
|
||||||
} else {
|
} else {
|
||||||
//console.log('[BlockDb.js.3782]', i++); //TODO
|
|
||||||
self._fillConfirmationsOne(txout,height, e_c);
|
self._fillConfirmationsOne(txout,height, e_c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,5 +380,9 @@ var i=0;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is for DB upgrades mainly
|
||||||
|
BlockDb.prototype._runScript = function(script, cb) {
|
||||||
|
db.batch(script,cb);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(BlockDb);
|
module.exports = require('soop')(BlockDb);
|
||||||
|
|
|
@ -329,13 +329,25 @@ HistoricSync.prototype.setupSyncStatus = function() {
|
||||||
this.syncPercentage = 0;
|
this.syncPercentage = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HistoricSync.prototype.checkDBVersion = function(cb) {
|
||||||
|
this.sync.txDb.checkVersion02(function(isOk){
|
||||||
|
if (!isOk) {
|
||||||
|
console.log('\n#############################\n\n ## Insight API DB is older that v0.2. Please resync using:\n $ util/sync.js -D\n More information at Insight API\'s Readme.md');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
// Add more test here in future changes.
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
HistoricSync.prototype.prepareToSync = function(opts, next) {
|
HistoricSync.prototype.prepareToSync = function(opts, next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.status = 'starting';
|
self.status = 'starting';
|
||||||
async.series([
|
async.series([
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.sync.txDb.checkVersion02(s_c);
|
self.checkDBVersion(s_c);
|
||||||
},
|
},
|
||||||
function(s_c) {
|
function(s_c) {
|
||||||
self.checkNetworkSettings(s_c);
|
self.checkNetworkSettings(s_c);
|
||||||
|
|
|
@ -664,11 +664,8 @@ TransactionDb.prototype.getPoolInfo = function(txid, cb) {
|
||||||
TransactionDb.prototype.checkVersion02 = function(cb) {
|
TransactionDb.prototype.checkVersion02 = function(cb) {
|
||||||
var k = 'txb-f0315ffc38709d70ad5647e22048358dd3745f3ce3874223c80a7c92fab0c8ba-00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
var k = 'txb-f0315ffc38709d70ad5647e22048358dd3745f3ce3874223c80a7c92fab0c8ba-00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206';
|
||||||
db.get(k, function(err, val) {
|
db.get(k, function(err, val) {
|
||||||
if (val) {
|
|
||||||
console.log('\n#############################\n\n ## Insight API DB is older that v0.2. Please resync using:\n $ util/sync.js -D\n More information at Insight API\'s Readme.md');
|
return cb(!val);
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
return cb();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var HistoricSync = require('../lib/HistoricSync');
|
||||||
|
var async = require('async');
|
||||||
|
|
||||||
|
//
|
||||||
|
// 1)
|
||||||
|
// var MAIN_PREFIX = 'bma-'; // bma-<hash> => <height> (0 is unconnected)
|
||||||
|
// var TIP = 'bti-'; // bti = <hash>:<height> last block on the chain
|
||||||
|
//
|
||||||
|
// var IN_BLK_PREFIX = 'btx-'; //btx-<txid> = <block>
|
||||||
|
// v
|
||||||
|
// 2) DELETE txs/tx-
|
||||||
|
// 3) DELETE txs/txb
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
var historicSync = new HistoricSync({ shouldBroadcastSync: false });
|
||||||
|
var txDb=historicSync.sync.txDb;
|
||||||
|
var bDb=historicSync.sync.bDb;
|
||||||
|
|
||||||
|
var height = 0;
|
||||||
|
var hash = historicSync.genesis;
|
||||||
|
var tipHash;
|
||||||
|
|
||||||
|
async.series([
|
||||||
|
function(c){
|
||||||
|
txDb.checkVersion02(function(isV2){
|
||||||
|
var err;
|
||||||
|
if(isV2) err='Already in v0.2!';
|
||||||
|
return c(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function(c){
|
||||||
|
var script=[];
|
||||||
|
async.whilst(
|
||||||
|
function() {
|
||||||
|
return hash;
|
||||||
|
},
|
||||||
|
function (w_cb) {
|
||||||
|
script=script.concat(bDb._setHeightScript(hash,height));
|
||||||
|
bDb.getNext(hash,function(err,val){
|
||||||
|
if (err) return w_cb(err);
|
||||||
|
tipHash = hash;
|
||||||
|
hash = val;
|
||||||
|
height++;
|
||||||
|
if (!(height%1000) || !hash) {
|
||||||
|
console.log('\t%d blocks processed (set height 1/2)', height);
|
||||||
|
bDb._runScript(script, function(err) {
|
||||||
|
script=[];
|
||||||
|
return w_cb(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else return w_cb();
|
||||||
|
});
|
||||||
|
}, c);
|
||||||
|
},
|
||||||
|
function(c){
|
||||||
|
bDb.setTip(tipHash, height-1, c);
|
||||||
|
},
|
||||||
|
],function(err){
|
||||||
|
if (err)
|
||||||
|
console.log('## '+err);
|
||||||
|
else
|
||||||
|
console.log('Finished OK.');
|
||||||
|
});
|
Loading…
Reference in New Issue