do not store orphan txs.
This commit is contained in:
parent
e8a70f9d7b
commit
7bf912f570
@ -233,7 +233,11 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
+ '/' + input.prevout.index);
|
+ '/' + input.prevout.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.del(p + 'u/t/' + input.prevout.hash + '/' + input.prevout.index);
|
batch.del(
|
||||||
|
p + 'u/t/'
|
||||||
|
+ input.prevout.hash
|
||||||
|
+ '/' + input.prevout.index);
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +264,7 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
|
|
||||||
if (orphans) {
|
if (orphans) {
|
||||||
try {
|
try {
|
||||||
orphans = JSON.parse(orphans.toString('utf8'));
|
orphans = JSON.parse(orphans.toString('ascii'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return done(e);
|
return done(e);
|
||||||
}
|
}
|
||||||
@ -269,11 +273,11 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
orphans.push({
|
orphans.push({
|
||||||
tx: tx.toExtended(true).toString('hex'),
|
tx: hash,
|
||||||
index: i
|
index: i
|
||||||
});
|
});
|
||||||
|
|
||||||
orphans = new Buffer(JSON.stringify(orphans), 'utf8');
|
orphans = new Buffer(JSON.stringify(orphans), 'ascii');
|
||||||
|
|
||||||
batch.put(p + 'o/' + key, orphans);
|
batch.put(p + 'o/' + key, orphans);
|
||||||
|
|
||||||
@ -307,43 +311,46 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
if (err && err.type !== 'NotFoundError')
|
if (err && err.type !== 'NotFoundError')
|
||||||
return done(err);
|
return done(err);
|
||||||
|
|
||||||
if (orphans) {
|
|
||||||
try {
|
|
||||||
orphans = JSON.parse(orphans.toString('utf8'));
|
|
||||||
orphans = orphans.map(function(orphan) {
|
|
||||||
var tx = new Buffer(orphan.tx, 'hex');
|
|
||||||
orphan.tx = bcoin.tx.fromExtended(tx, true);
|
|
||||||
return orphan;
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
return next(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add input to orphan
|
// Add input to orphan
|
||||||
if (orphans) {
|
if (orphans) {
|
||||||
some = false;
|
some = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
orphans = JSON.parse(new Buffer(orphans, 'ascii'));
|
||||||
|
} catch (e) {
|
||||||
|
return done(e);
|
||||||
|
}
|
||||||
|
|
||||||
utils.forEachSerial(orphans, function(orphan, next, j) {
|
utils.forEachSerial(orphans, function(orphan, next, j) {
|
||||||
if (some)
|
if (some)
|
||||||
return next();
|
return next();
|
||||||
|
|
||||||
orphan.tx.inputs[orphan.index].output = coin;
|
self.getTX(orphan.tx, function(err, otx) {
|
||||||
|
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
|
||||||
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
|
||||||
|
|
||||||
// Verify that input script is correct, if not - add
|
|
||||||
// output to unspent and remove orphan from storage
|
|
||||||
if (orphan.tx.verify(orphan.index)) {
|
|
||||||
some = true;
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.remove(orphan.tx, function(err) {
|
|
||||||
if (err)
|
if (err)
|
||||||
return next(err);
|
return done(err);
|
||||||
return next();
|
|
||||||
|
// Probably removed by some other means.
|
||||||
|
if (!otx)
|
||||||
|
return next();
|
||||||
|
|
||||||
|
orphan.tx = otx;
|
||||||
|
orphan.tx.inputs[orphan.index].output = coin;
|
||||||
|
|
||||||
|
assert(orphan.tx.inputs[orphan.index].prevout.hash === hash);
|
||||||
|
assert(orphan.tx.inputs[orphan.index].prevout.index === i);
|
||||||
|
|
||||||
|
// Verify that input script is correct, if not - add
|
||||||
|
// output to unspent and remove orphan from storage
|
||||||
|
if (orphan.tx.verify(orphan.index)) {
|
||||||
|
some = true;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.remove(orphan.tx, function(err) {
|
||||||
|
if (err)
|
||||||
|
return next(err);
|
||||||
|
return next();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err)
|
if (err)
|
||||||
@ -371,8 +378,12 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
|||||||
if (type === 'pubkey' || type === 'multisig')
|
if (type === 'pubkey' || type === 'multisig')
|
||||||
address = null;
|
address = null;
|
||||||
|
|
||||||
if (address)
|
if (address) {
|
||||||
batch.put(p + 'u/a/' + address + '/' + hash + '/' + i, new Buffer([]));
|
batch.put(
|
||||||
|
p + 'u/a/' + address
|
||||||
|
+ '/' + hash + '/' + i,
|
||||||
|
new Buffer([]));
|
||||||
|
}
|
||||||
|
|
||||||
batch.put(p + 'u/t/' + hash + '/' + i, coin.toRaw());
|
batch.put(p + 'u/t/' + hash + '/' + i, coin.toRaw());
|
||||||
updated = true;
|
updated = true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user