parent
05939b5f24
commit
cc3db0583c
@ -1070,13 +1070,13 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
if (orphan) {
|
if (orphan) {
|
||||||
// If the orphan chain forked, simply
|
// If the orphan chain forked, simply
|
||||||
// reset the orphans and find a new peer.
|
// reset the orphans and find a new peer.
|
||||||
if (orphan.hash !== hash) {
|
if (orphan.hash('hex') !== hash) {
|
||||||
self.purgeOrphans();
|
self.purgeOrphans();
|
||||||
self.purgePending();
|
self.purgePending();
|
||||||
|
|
||||||
self.emit('fork', block, {
|
self.emit('fork', block, {
|
||||||
height: -1,
|
height: -1,
|
||||||
expected: orphan.hash,
|
expected: orphan.hash('hex'),
|
||||||
received: hash,
|
received: hash,
|
||||||
checkpoint: false
|
checkpoint: false
|
||||||
}, peer);
|
}, peer);
|
||||||
@ -1103,22 +1103,15 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
// If previous block wasn't ever seen,
|
// If previous block wasn't ever seen,
|
||||||
// add it current to orphans and break.
|
// add it current to orphans and break.
|
||||||
if (prevHeight === -1) {
|
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, {
|
self.emit('orphan', block, {
|
||||||
height: -1,
|
height: -1,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
seen: false
|
seen: false
|
||||||
}, peer);
|
}, 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();
|
return done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1295,17 +1288,10 @@ Chain.prototype.add = function add(initial, peer, callback, force) {
|
|||||||
|
|
||||||
// An orphan chain was found, start resolving.
|
// An orphan chain was found, start resolving.
|
||||||
block = self.orphan.map[hash];
|
block = self.orphan.map[hash];
|
||||||
delete self.orphan.bmap[block.hash];
|
delete self.orphan.bmap[block.hash('hex')];
|
||||||
delete self.orphan.map[hash];
|
delete self.orphan.map[hash];
|
||||||
self.orphan.count--;
|
self.orphan.count--;
|
||||||
self.orphan.size -= block.data.length;
|
self.orphan.size -= block.getSize();
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
next(block);
|
next(block);
|
||||||
}
|
}
|
||||||
@ -1352,11 +1338,11 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
|
|||||||
|
|
||||||
best = Object.keys(this.orphan.map).reduce(function(best, prevBlock, i) {
|
best = Object.keys(this.orphan.map).reduce(function(best, prevBlock, i) {
|
||||||
var orphan = self.orphan.map[prevBlock];
|
var orphan = self.orphan.map[prevBlock];
|
||||||
var height = orphan.coinbaseHeight;
|
var height = orphan.getCoinbaseHeight();
|
||||||
|
|
||||||
last = orphan;
|
last = orphan;
|
||||||
|
|
||||||
if (!best || height > best.coinbaseHeight)
|
if (!best || height > best.getCoinbaseHeight())
|
||||||
return orphan;
|
return orphan;
|
||||||
|
|
||||||
return best;
|
return best;
|
||||||
@ -1364,12 +1350,12 @@ Chain.prototype.pruneOrphans = function pruneOrphans(peer) {
|
|||||||
|
|
||||||
// Save the best for last... or the
|
// Save the best for last... or the
|
||||||
// last for the best in this case.
|
// last for the best in this case.
|
||||||
if (!best || best.coinbaseHeight <= 0)
|
if (!best || best.getCoinbaseHeight() <= 0)
|
||||||
best = last;
|
best = last;
|
||||||
|
|
||||||
this.emit('purge',
|
this.emit('purge',
|
||||||
this.orphan.count - (best ? 1 : 0),
|
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) {
|
Object.keys(this.orphan.bmap).forEach(function(hash) {
|
||||||
var orphan = self.orphan.bmap[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.map[best.prevBlock] = best;
|
||||||
this.orphan.bmap[best.hash('hex')] = best;
|
this.orphan.bmap[best.hash('hex')] = best;
|
||||||
this.orphan.count++;
|
this.orphan.count++;
|
||||||
this.orphan.size += best.data.length;
|
this.orphan.size += best.getSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.purgePending = function purgePending() {
|
Chain.prototype.purgePending = function purgePending() {
|
||||||
|
|||||||
@ -663,7 +663,7 @@ MTX.prototype.maxSize = function maxSize(maxM, maxN) {
|
|||||||
for (i = 0; i < copy.inputs.length; i++)
|
for (i = 0; i < copy.inputs.length; i++)
|
||||||
copy.inputs[i].script = [];
|
copy.inputs[i].script = [];
|
||||||
|
|
||||||
total = copy.render(true).length;
|
total = copy.render().length;
|
||||||
|
|
||||||
// Add size for signatures and public keys
|
// Add size for signatures and public keys
|
||||||
for (i = 0; i < copy.inputs.length; i++) {
|
for (i = 0; i < copy.inputs.length; i++) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user