From ef7ec2328dce7cce7d7d84bfd240245241106653 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 27 May 2014 16:14:44 -0300 Subject: [PATCH] upgrade script --- lib/BlockDb.js | 38 +++++++++++++++++++++++++++++++++++++- lib/TransactionDb.js | 2 ++ util/updateToV0.2.js | 24 ++++++++++-------------- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 891ac4aa..b8e67b04 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -380,9 +380,45 @@ BlockDb.prototype.fillConfirmations = function(txouts, cb) { }); }; -// This is for DB upgrades mainly +/* this is only for migration scripts */ BlockDb.prototype._runScript = function(script, cb) { db.batch(script,cb); }; +BlockDb.prototype.migrateV02 = function(cb) { + var k = 'txb-'; + this.txDb._db.createReadStream({ + start: k, + end: k + '~' + }).pipe(db.createWriteStream()).on('close', cb); +}; + +BlockDb.prototype.migrateV02cleanup = function(cb) { + + var self = this; + console.log('## deleting txb- from txs db'); //todo + + var k = 'txb-'; + var d = this.txDb._db; + d.createReadStream({ + start: k, + end: k + '~' + }) + .pipe(d.createWriteStream({type:'del'})) + .on('close', function(err){ + if (err) return cb(err); + console.log('## deleting tx- from txs db'); //todo + + var k = 'tx-'; + var d = self.txDb._db; + d.createReadStream({ + start: k, + end: k + '~' + }) + .pipe(d.createWriteStream({type:'del'})) + .on('close',cb); + }); +}; + + module.exports = require('soop')(BlockDb); diff --git a/lib/TransactionDb.js b/lib/TransactionDb.js index ffd19b5d..e7a203e5 100644 --- a/lib/TransactionDb.js +++ b/lib/TransactionDb.js @@ -59,6 +59,8 @@ var TransactionDb = function() { this.network = config.network === 'testnet' ? networks.testnet : networks.livenet; this.poolMatch = new PoolMatch(); this.safeConfirmations = config.safeConfirmations || DEFAULT_SAFE_CONFIRMATIONS; + + this._db = db; // this is only exposed for migration script }; TransactionDb.prototype.close = function(cb) { diff --git a/util/updateToV0.2.js b/util/updateToV0.2.js index 5f165009..2e79ff39 100755 --- a/util/updateToV0.2.js +++ b/util/updateToV0.2.js @@ -5,17 +5,6 @@ var HistoricSync = require('../lib/HistoricSync'); var async = require('async'); -// -// 1) -// var MAIN_PREFIX = 'bma-'; // bma- => (0 is unconnected) -// var TIP = 'bti-'; // bti = : last block on the chain -// -// var IN_BLK_PREFIX = 'btx-'; //btx- = -// v -// 2) DELETE txs/tx- -// 3) DELETE txs/txb -// - var historicSync = new HistoricSync({ shouldBroadcastSync: false }); var txDb=historicSync.sync.txDb; @@ -45,9 +34,9 @@ async.series([ if (err) return w_cb(err); tipHash = hash; hash = val; - height++; + if (hash) height++; if (!(height%1000) || !hash) { - console.log('\t%d blocks processed (set height 1/2)', height); + console.log('*update 1/2\t%d blocks processed', height); bDb._runScript(script, function(err) { script=[]; return w_cb(err); @@ -58,7 +47,14 @@ async.series([ }, c); }, function(c){ - bDb.setTip(tipHash, height-1, c); + console.log('Migrating txs... (this will take some minutes...)'); //TODO + bDb.migrateV02(c); + }, + function(c){ + bDb.setTip(tipHash, height, c); + }, + function(c){ + bDb.migrateV02cleanup(c); }, ],function(err){ if (err)