Revert "keep orphans off the heap."

This reverts commit 466429dbe2.
This commit is contained in:
Christopher Jeffrey 2016-02-24 14:31:32 -08:00
parent 05939b5f24
commit cc3db0583c
2 changed files with 14 additions and 28 deletions

View File

@ -1070,13 +1070,13 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
if (orphan) {
// If the orphan chain forked, simply
// reset the orphans and find a new peer.
if (orphan.hash !== hash) {
if (orphan.hash('hex') !== hash) {
self.purgeOrphans();
self.purgePending();
self.emit('fork', block, {
height: -1,
expected: orphan.hash,
expected: orphan.hash('hex'),
received: hash,
checkpoint: false
}, peer);
@ -1103,22 +1103,15 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
// If previous block wasn't ever seen,
// add it current to orphans and break.
if (prevHeight === -1) {
self.orphan.count++;
self.orphan.size += block.getSize();
self.orphan.map[prevHash] = block;
self.orphan.bmap[hash] = block;
self.emit('orphan', block, {
height: -1,
hash: hash,
seen: false
}, peer);
block = {
data: block._raw,
type: block.type,
hash: block.hash('hex'),
prevBlock: block.prevBlock,
coinbaseHeight: block.getCoinbaseHeight()
};
self.orphan.count++;
self.orphan.size += block.data.length;
self.orphan.map[prevHash] = block;
self.orphan.bmap[hash] = block;
return done();
}
@ -1295,17 +1288,10 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
// An orphan chain was found, start resolving.
block = self.orphan.map[hash];
delete self.orphan.bmap[block.hash];
delete self.orphan.bmap[block.hash('hex')];
delete self.orphan.map[hash];
self.orphan.count--;
self.orphan.size -= block.data.length;
if (block.type === 'block')
block = bcoin.block.fromRaw(block.data);
else if (block.type === 'merkleblock')
block = bcoin.merkleblock.fromRaw(block.data);
else if (block.type === 'headers')
block = bcoin.headers.fromRaw(block.data);
self.orphan.size -= block.getSize();
next(block);
}
@ -1352,11 +1338,11 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
best = Object.keys(this.orphan.map).reduce(function(best, prevBlock, i) {
var orphan = self.orphan.map[prevBlock];
var height = orphan.coinbaseHeight;
var height = orphan.getCoinbaseHeight();
last = orphan;
if (!best || height > best.coinbaseHeight)
if (!best || height > best.getCoinbaseHeight())
return orphan;
return best;
@ -1364,12 +1350,12 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
// Save the best for last... or the
// last for the best in this case.
if (!best || best.coinbaseHeight <= 0)
if (!best || best.getCoinbaseHeight() <= 0)
best = last;
this.emit('purge',
this.orphan.count - (best ? 1 : 0),
this.orphan.size - (best ? best.data.length : 0));
this.orphan.size - (best ? best.getSize() : 0));
Object.keys(this.orphan.bmap).forEach(function(hash) {
var orphan = self.orphan.bmap[hash];
@ -1388,7 +1374,7 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
this.orphan.map[best.prevBlock] = best;
this.orphan.bmap[best.hash('hex')] = best;
this.orphan.count++;
this.orphan.size += best.data.length;
this.orphan.size += best.getSize();
};
Chain.prototype.purgePending = function purgePending() {

View File

@ -663,7 +663,7 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
for (i = 0; i < copy.inputs.length; i++)
copy.inputs[i].script = [];
total = copy.render(true).length;
total = copy.render().length;
// Add size for signatures and public keys
for (i = 0; i < copy.inputs.length; i++) {