From 601318f0e18ec83786f08b6100a2d45756197abe Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 17 Feb 2014 15:04:01 -0300 Subject: [PATCH] pool match - WIP --- config/config.js | 1 + dev-util/get_block.js | 8 +- etc/minersPoolStrings.json | 163 +++++++++++++++++++++++++++++++++++++ insight.js | 7 +- lib/BlockDb.js | 4 + lib/HistoricSync.js | 17 ++-- lib/PoolMatch.js | 46 +++++++++++ lib/Rpc.js | 2 - lib/Sync.js | 4 + 9 files changed, 236 insertions(+), 16 deletions(-) create mode 100644 etc/minersPoolStrings.json create mode 100644 lib/PoolMatch.js diff --git a/config/config.js b/config/config.js index f5e2384..fbf585c 100644 --- a/config/config.js +++ b/config/config.js @@ -65,6 +65,7 @@ module.exports = { network: process.env.INSIGHT_NETWORK || 'testnet', disableP2pSync: false, disableHistoricSync: false, + poolMatchFile: './etc/minersPoolStrings.json', // Time to refresh the currency rate. In minutes currencyRefresh: 10 diff --git a/dev-util/get_block.js b/dev-util/get_block.js index fe3e416..f65d8c3 100755 --- a/dev-util/get_block.js +++ b/dev-util/get_block.js @@ -10,14 +10,14 @@ var RpcClient = require('../node_modules/bitcore/RpcClient').class(); var config = require('../config/config'); -// var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4'; -var hash = process.argv[2] || 'f6c2901f39fd07f2f2e503183d76f73ecc1aee9ac9216fde58e867bc29ce674e'; + var hash = process.argv[2] || '0000000000b6288775bbd326bedf324ca8717a15191da58391535408205aada4'; +//var hash = process.argv[2] || 'f6c2901f39fd07f2f2e503183d76f73ecc1aee9ac9216fde58e867bc29ce674e'; -hash = 'e2253359458db3e732c82a43fc62f56979ff59928f25a2df34dfa443e9a41160'; +//hash = 'e2253359458db3e732c82a43fc62f56979ff59928f25a2df34dfa443e9a41160'; var rpc = new RpcClient(config.bitcoind); -rpc.getBlockCount( function(err, ret) { +rpc.getBlock( hash, function(err, ret) { console.log('Err:'); console.log(err); diff --git a/etc/minersPoolStrings.json b/etc/minersPoolStrings.json new file mode 100644 index 0000000..bbe8b2b --- /dev/null +++ b/etc/minersPoolStrings.json @@ -0,0 +1,163 @@ +[ + { + "poolName":"50BTC", + "url":"https://50btc.com/", + "searchStrings":[ + "50BTC.com" + ] + }, + { + "poolName":"175btc", + "url":"http://www.175btc.com/", + "searchStrings":[ + "Mined By 175btc.com" + ] + }, + { + "poolName":"ASICminer", + "url":"https://bitcointalk.org/index.php?topic=99497.0", + "searchStrings":[ + "Mined By ASICMiner" + ] + }, + { + "poolName":"BitMinter", + "url":"https://bitminter.com/", + "searchStrings":[ + "BitMinter" + ] + }, + { + "poolName":"Bitparking", + "url":"http://bitparking.com/", + "searchStrings":[ + "bitparking" + ] + }, + { + "poolName":"BTC Guild", + "url":"https://www.btcguild.com/", + "searchStrings":[ + "Mined by BTC Guild", + "BTC Guild" + ] + }, + { + "poolName":"Discus Fish", + "url":"http://f2pool.com/", + "searchStrings":[ + "七彩神仙鱼", + "Made in China", + "Mined by user" + ] + }, + { + "poolName":"Discus Fish Solo", + "url":"http://f2pool.com/", + "searchStrings":[ + "For Pierce and Paul" + ] + }, + { + "poolName":"Eligius", + "url":"http://eligius.st/", + "searchStrings":[ + "Eligius" + ] + }, + { + "poolName":"EclipseMC", + "url":"https://eclipsemc.com/", + "searchStrings":[ + "Josh Zerlan was here!", + "EclipseMC", + "Aluminum Falcons" + ] + }, + { + "poolName":"GIVE-ME-COINS", + "url":"https://give-me-coins.com/", + "searchStrings":[ + "Mined at GIVE-ME-COINS.com" + ] + }, + { + "poolName":"ghash.io", + "url":"https://ghash.io/", + "searchStrings":[ + "ghash.io", + "GHash.IO" + ] + }, + { + "poolName":"Horrible Horrendous Terrible Tremendous", + "url":"http://hhtt.1209k.com/", + "searchStrings":[ + "HHTT" + ] + }, + { + "poolName":"Megabigpower", + "url":"http://megabigpower.com/", + "searchStrings":[ + "megabigpower.com" + ] + }, + { + "poolName":"Mt Red", + "url":"https://mtred.com/‎", + "searchStrings":[ + "/mtred/" + ] + }, + { + "poolName":"MaxBTC", + "url":"https://www.maxbtc.com", + "searchStrings":[ + "MaxBTC" + ] + }, + { + "poolName":"ozcoin", + "url":"https://ozco.in/", + "searchStrings":[ + "ozco.in", + "ozcoin" + ] + }, + { + "poolName":"Polmine.pl", + "url":"https://polmine.pl/‎", + "searchStrings":[ + "by polmine.pl" + ] + }, + { + "poolName":"simplecoin", + "url":"http://simplecoin.us/", + "searchStrings":[ + "simplecoin.us ftw" + ] + }, + { + "poolName":"Slush", + "url":"https://mining.bitcoin.cz/", + "searchStrings":[ + "slush" + ] + }, + { + "poolName":"TripleMining", + "url":"https://www.triplemining.com/", + "searchStrings":[ + "Triplemining.com" + ] + }, + { + "poolName":"Yourbtc.net", + "url":"http://yourbtc.net/", + "searchStrings":[ + "yourbtc.net" + ] + } +] \ No newline at end of file diff --git a/insight.js b/insight.js index 92dbdd7..42b0b97 100644 --- a/insight.js +++ b/insight.js @@ -73,9 +73,12 @@ if (!config.disableHistoricSync) { else { historicSync.smartImport({}, function(err){ var txt = 'ended.'; - if (err) txt = 'ABORTED with error: ' + err.message; - else + if (err) + txt = 'ABORTED with error: ' + err.message; + else if (ps) { ps.allowReorgs = true; + ps.historicSync = historicSync; + } console.log('[historic_sync] ' + txt, historicSync.info()); }); diff --git a/lib/BlockDb.js b/lib/BlockDb.js index 1cb232e..76a118c 100644 --- a/lib/BlockDb.js +++ b/lib/BlockDb.js @@ -23,10 +23,13 @@ function spec(b) { config = require('../config/config'); var db = b.db || levelup(config.leveldb + '/blocks',{maxOpenFiles: MAX_OPEN_FILES} ); var Rpc = b.rpc || require('./Rpc').class(); + var PoolMatch = b.poolMatch || require('./PoolMatch').class(config); var BlockDb = function() { BlockDb.super(this, arguments); + this.poolMatch = new PoolMatch(); }; + BlockDb.superclass = superclass; BlockDb.prototype.close = function(cb) { @@ -172,6 +175,7 @@ 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, diff --git a/lib/HistoricSync.js b/lib/HistoricSync.js index 48f4313..aa557ac 100644 --- a/lib/HistoricSync.js +++ b/lib/HistoricSync.js @@ -28,14 +28,6 @@ function spec() { this.genesis = genesisHashReversed.reverse().toString('hex'); - //available status: starting / syncing / finished / aborted - this.status = 'starting'; - this.error = null; - - this.syncPercentage = 0; - this.syncedBlocks = 0; - this.orphanBlocks = 0; - this.type =''; } function p() { @@ -343,6 +335,15 @@ function spec() { var lastBlock; var tip; + //available status: starting / syncing / finished / aborted + this.status = 'starting'; + this.error = null; + + this.syncPercentage = 0; + this.syncedBlocks = 0; + this.orphanBlocks = 0; + this.type =''; + async.series([ function(s_c) { if (!scanOpts.destroy) return s_c(); diff --git a/lib/PoolMatch.js b/lib/PoolMatch.js new file mode 100644 index 0000000..8c8db66 --- /dev/null +++ b/lib/PoolMatch.js @@ -0,0 +1,46 @@ +'use strict'; + +require('classtool'); + +function spec(b) { + + var fs = require('fs'); + var buffertools = require('buffertools'); + var db = b.db || JSON.parse( fs.readFileSync(b.poolMatchFile || './poolMatchFile.json')); + + var PoolMatch = function() { + var self = this; + + self.strings={}; + db.forEach(function(pool) { + pool.searchStrings.forEach(function(s) { + if (!self.strings[s]) self.strings[s] = []; + self.strings[s].push(pool); + }); + }); + Object.keys( self.strings, function(s) { + delete self.strings[s].searchStrings; + }); + self.stringsK = Object.keys(self.strings); + self.stringsKl = self.stringsK.length; + }; + + PoolMatch.prototype.match = function(buffer) { + var self = this; + + var match; + var i =0; + while (!match && i < self.stringsKl) { + var k = self.stringsK[i++]; + if ( buffertools.indexOf(buffer,self.strings[k]) >= 0 ) { + match = self.strings[k]; + } + } + return match; + }; + + return PoolMatch; +} +module.defineClass(spec); + + diff --git a/lib/Rpc.js b/lib/Rpc.js index b13e112..3025bdd 100644 --- a/lib/Rpc.js +++ b/lib/Rpc.js @@ -93,8 +93,6 @@ function spec(b) { return cb(err,info.result); }); }; - - return Rpc; } module.defineClass(spec); diff --git a/lib/Sync.js b/lib/Sync.js index a6afc6d..6a21627 100644 --- a/lib/Sync.js +++ b/lib/Sync.js @@ -103,6 +103,10 @@ function spec() { self.bDb.has(newPrev, function(err, val) { if (!val && newPrev.match(/^0+$/)) return c(); +/// AQUI! -> return is reor... + // + // needSync + // => return c(err || (!val ? new Error('WARN: Ignoring block with non existing prev:' + b.hash) : null)); });