add txs to mempool before removing.

This commit is contained in:
Christopher Jeffrey 2016-05-06 13:56:40 -07:00
parent 2b2598a892
commit 5d1e3e1034
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 55 additions and 19 deletions

View File

@ -205,36 +205,72 @@ Mempool.prototype.addBlock = function addBlock(block, callback, force) {
callback = utils.wrap(callback, unlock);
utils.forEachSerial(block.txs, function(tx, next) {
var hash = tx.hash('hex');
var copy;
// We add the txs we haven't seen to
// the mempool first to potentially
// resolve orphans.
utils.forEachSerial(block.txs, function(tx, next) {
var hash, copy;
if (!self.chain.isFull())
return next();
if (tx.isCoinbase())
return next();
self.getTX(hash, function(err, existing) {
hash = tx.hash('hex');
self.hasTX(hash, function(err, exists) {
if (err)
return callback(err);
return next(err);
if (!existing)
return self.removeOrphan(hash, next);
if (exists)
return next();
copy = tx.clone();
copy.ts = existing.ts;
copy.block = existing.block;
copy.height = existing.height;
copy.ps = existing.ps;
self.removeUnchecked(copy, function(err) {
self.removeOrphan(hash, function(err) {
if (err)
return next(err);
self.emit('confirmed', tx, block);
copy = tx.clone();
copy.unsetBlock();
return next();
self.addUnchecked(tx, next);
});
});
}, callback);
}, function(err) {
if (err)
return callback(err);
utils.forEachSerial(block.txs.slice().reverse(), function(tx, next) {
var hash = tx.hash('hex');
var copy;
if (tx.isCoinbase())
return next();
self.getTX(hash, function(err, existing) {
if (err)
return next(err);
if (!existing)
return self.removeOrphan(hash, next);
copy = tx.clone();
copy.ts = existing.ts;
copy.block = existing.block;
copy.height = existing.height;
copy.ps = existing.ps;
self.removeUnchecked(copy, function(err) {
if (err)
return next(err);
self.emit('confirmed', tx, block);
return next();
});
});
}, callback);
});
};
/**
@ -253,7 +289,7 @@ Mempool.prototype.removeBlock = function removeBlock(block, callback, force) {
callback = utils.wrap(callback, unlock);
utils.forEachSerial(block.txs.slice().reverse(), function(tx, next) {
utils.forEachSerial(block.txs, function(tx, next) {
var copy;
if (tx.isCoinbase())

View File

@ -509,7 +509,7 @@ testnet.block = {
pruneAfterHeight: 1000,
// maxTipAge: 0x7fffffff
maxTipAge: 24 * 60 * 60,
slowHeight: 500000
slowHeight: 750000
};
testnet.witness = false;