fixes.
This commit is contained in:
parent
d78a727de8
commit
67e739ef39
@ -35,15 +35,15 @@ function BlockDB(node, options) {
|
||||
bcoin.ensurePrefix();
|
||||
|
||||
if (!this.file)
|
||||
this.file = bcoin.prefix + '/index-' + network.type + '.db';
|
||||
this.file = bcoin.prefix + '/block-' + network.type + '.db';
|
||||
|
||||
this.options = options;
|
||||
|
||||
this.node = node;
|
||||
|
||||
this.cache = {
|
||||
unspent: new bcoin.lru(32 * 1024 * 1024),
|
||||
tx: new bcoin.lru(32 * 1024 * 1024)
|
||||
unspent: new bcoin.lru(32 * 1024 * 1024, function() { return 80; }),
|
||||
tx: new bcoin.lru(32 * 1024 * 1024, function(tx) { return tx.getSize(); })
|
||||
};
|
||||
|
||||
if (+process.env.BCOIN_FRESH === 1 && bcoin.cp)
|
||||
|
||||
@ -275,6 +275,9 @@ Chain.prototype._preload = function _preload(callback) {
|
||||
if (!this.options.preload)
|
||||
return callback();
|
||||
|
||||
if (!this.options.spv)
|
||||
return callback();
|
||||
|
||||
if (network.type !== 'main')
|
||||
return callback(new Error('Electrum.org only offers `main` headers.'));
|
||||
|
||||
@ -484,6 +487,8 @@ Chain.prototype._verify = function _verify(block, prev, callback) {
|
||||
|
||||
if (block.bits !== self.getTarget(prev, block)) {
|
||||
utils.debug('Block is using wrong target: %s', block.rhash);
|
||||
utils.debug('Has %d, expected: %d',
|
||||
block.bits, self.getTarget(prev, block));
|
||||
return done(null, false);
|
||||
}
|
||||
|
||||
|
||||
@ -178,8 +178,10 @@ ChainBlock.prototype._alloc = function _alloc(max, callback) {
|
||||
if (this.previous.length >= max)
|
||||
return callback();
|
||||
|
||||
if (!this.chain.db.hasCache(entry.prevBlock))
|
||||
if (!this.chain.db.hasCache(entry.prevBlock)) {
|
||||
this.previous.pop();
|
||||
break;
|
||||
}
|
||||
|
||||
entry = this.chain.db.getCache(entry.prevBlock);
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ function ChainDB(node, chain, options) {
|
||||
// http://hur.st/bloomfilter?n=800000&p=0.01 (m=936kb, k=7)
|
||||
// 10% false positive rate for 800k blocks
|
||||
// http://hur.st/bloomfilter?n=800000&p=0.10 (m=468kb, k=3)
|
||||
this.bloom = new bcoin.bloom(937 * 1024, 7, 0xdeadbeef);
|
||||
// this.bloom = new bcoin.bloom(937 * 1024, 7, 0xdeadbeef);
|
||||
|
||||
// Need to cache up to the retarget interval
|
||||
// if we're going to be checking the damn
|
||||
@ -68,6 +68,8 @@ function ChainDB(node, chain, options) {
|
||||
|
||||
this.cacheHash = new DumbCache(this._cacheWindow * 200); // (not hashcash)
|
||||
this.cacheHeight = new DumbCache(this._cacheWindow * 200);
|
||||
// this.cacheHash = new bcoin.lru(this._cacheWindow, function() { return 1; }); // (not hashcash)
|
||||
// this.cacheHeight = new bcoin.lru(this._cacheWindow, function() { return 1; });
|
||||
|
||||
this._init();
|
||||
}
|
||||
@ -130,8 +132,10 @@ ChainDB.prototype.load = function load(callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
this.has(genesis.hash, function(err, exists) {
|
||||
assert(!err);
|
||||
this.db.get('c/h/' + genesis.hash, function(err, exists) {
|
||||
if (err && err.type !== 'NotFoundError')
|
||||
throw err;
|
||||
|
||||
if (!exists)
|
||||
self.save(genesis, finish);
|
||||
else
|
||||
@ -183,8 +187,8 @@ ChainDB.prototype.getHeight = function getHeight(hash, callback) {
|
||||
if (this.cacheHash.has(hash))
|
||||
return callback(null, this.cacheHash.get(hash).height);
|
||||
|
||||
if (!this.bloom.test(hash, 'hex'))
|
||||
return callback(null, -1);
|
||||
// if (!this.bloom.test(hash, 'hex'))
|
||||
// return callback(null, -1);
|
||||
|
||||
this.db.get('c/h/' + hash, function(err, height) {
|
||||
if (err && err.type !== 'NotFoundError')
|
||||
@ -218,6 +222,45 @@ ChainDB.prototype.getHash = function getHash(height, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.dump = function dump(callback) {
|
||||
var self = this;
|
||||
var records = {};
|
||||
|
||||
var iter = this.db.db.iterator({
|
||||
gte: 'c',
|
||||
lte: 'c~',
|
||||
keys: true,
|
||||
values: true,
|
||||
fillCache: false,
|
||||
keyAsBuffer: false,
|
||||
valueAsBuffer: true
|
||||
});
|
||||
|
||||
callback = utils.ensure(callback);
|
||||
|
||||
(function next() {
|
||||
iter.next(function(err, key, value) {
|
||||
if (err) {
|
||||
return iter.end(function() {
|
||||
callback(err);
|
||||
});
|
||||
}
|
||||
|
||||
if (key === undefined) {
|
||||
return iter.end(function(err) {
|
||||
if (err)
|
||||
return callback(err);
|
||||
return callback(null, records);
|
||||
});
|
||||
}
|
||||
|
||||
records[key] = value;
|
||||
|
||||
next();
|
||||
});
|
||||
})();
|
||||
};
|
||||
|
||||
ChainDB.prototype.getChainHeight = function getChainHeight(callback) {
|
||||
return this.getTip(function(err, entry) {
|
||||
if (err)
|
||||
@ -327,7 +370,7 @@ ChainDB.prototype.save = function save(entry, callback) {
|
||||
// (necessary for isSuperMajority)
|
||||
this.addCache(entry);
|
||||
|
||||
this.bloom.add(entry.hash, 'hex');
|
||||
// this.bloom.add(entry.hash, 'hex');
|
||||
|
||||
batch = this.db.batch();
|
||||
height = new Buffer(4);
|
||||
|
||||
@ -204,7 +204,7 @@ Pool.prototype._init = function _init() {
|
||||
if (!peer)
|
||||
return;
|
||||
|
||||
self.setMisbehavior(peer, 1);
|
||||
// self.setMisbehavior(peer, 1);
|
||||
});
|
||||
|
||||
this.chain.on('orphan', function(block, data, peer) {
|
||||
@ -215,7 +215,7 @@ Pool.prototype._init = function _init() {
|
||||
|
||||
// Increase banscore by 10 if we're using getheaders.
|
||||
if (self.options.headers) {
|
||||
self.setMisbehavior(peer, 10);
|
||||
// self.setMisbehavior(peer, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ function TX(data, block, index) {
|
||||
this.locktime = data.locktime || 0;
|
||||
this.ts = data.ts || 0;
|
||||
this.block = data.block || null;
|
||||
this.index = data.index || -1;
|
||||
this.index = data.index != null ? data.index : -1;
|
||||
this.ps = this.ts === 0 ? utils.now() : 0;
|
||||
|
||||
this._hash = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user