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);
|
||||
}
|
||||
|
||||
batch.del(p + 'u/t/' + input.prevout.hash + '/' + input.prevout.index);
|
||||
batch.del(
|
||||
p + 'u/t/'
|
||||
+ input.prevout.hash
|
||||
+ '/' + input.prevout.index);
|
||||
|
||||
return next();
|
||||
}
|
||||
|
||||
@ -260,7 +264,7 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
||||
|
||||
if (orphans) {
|
||||
try {
|
||||
orphans = JSON.parse(orphans.toString('utf8'));
|
||||
orphans = JSON.parse(orphans.toString('ascii'));
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
@ -269,11 +273,11 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
||||
}
|
||||
|
||||
orphans.push({
|
||||
tx: tx.toExtended(true).toString('hex'),
|
||||
tx: hash,
|
||||
index: i
|
||||
});
|
||||
|
||||
orphans = new Buffer(JSON.stringify(orphans), 'utf8');
|
||||
orphans = new Buffer(JSON.stringify(orphans), 'ascii');
|
||||
|
||||
batch.put(p + 'o/' + key, orphans);
|
||||
|
||||
@ -307,43 +311,46 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
||||
if (err && err.type !== 'NotFoundError')
|
||||
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
|
||||
if (orphans) {
|
||||
some = false;
|
||||
|
||||
try {
|
||||
orphans = JSON.parse(new Buffer(orphans, 'ascii'));
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
|
||||
utils.forEachSerial(orphans, function(orphan, next, j) {
|
||||
if (some)
|
||||
return next();
|
||||
|
||||
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) {
|
||||
self.getTX(orphan.tx, function(err, otx) {
|
||||
if (err)
|
||||
return next(err);
|
||||
return next();
|
||||
return done(err);
|
||||
|
||||
// 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) {
|
||||
if (err)
|
||||
@ -371,8 +378,12 @@ TXPool.prototype._add = function add(tx, callback, force) {
|
||||
if (type === 'pubkey' || type === 'multisig')
|
||||
address = null;
|
||||
|
||||
if (address)
|
||||
batch.put(p + 'u/a/' + address + '/' + hash + '/' + i, new Buffer([]));
|
||||
if (address) {
|
||||
batch.put(
|
||||
p + 'u/a/' + address
|
||||
+ '/' + hash + '/' + i,
|
||||
new Buffer([]));
|
||||
}
|
||||
|
||||
batch.put(p + 'u/t/' + hash + '/' + i, coin.toRaw());
|
||||
updated = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user