pool/peer: do not allow duplicate txs in merkle blocks.
This commit is contained in:
parent
bfca120f4f
commit
4aecaf9158
@ -117,6 +117,7 @@ function Peer(options) {
|
|||||||
this.merkleBlock = null;
|
this.merkleBlock = null;
|
||||||
this.merkleTime = -1;
|
this.merkleTime = -1;
|
||||||
this.merkleMatches = 0;
|
this.merkleMatches = 0;
|
||||||
|
this.merkleMap = null;
|
||||||
this.syncing = false;
|
this.syncing = false;
|
||||||
this.sentAddr = false;
|
this.sentAddr = false;
|
||||||
this.sentGetAddr = false;
|
this.sentGetAddr = false;
|
||||||
|
|||||||
@ -736,6 +736,7 @@ Pool.prototype.stopSync = function stopSync() {
|
|||||||
peer.merkleBlock = null;
|
peer.merkleBlock = null;
|
||||||
peer.merkleTime = -1;
|
peer.merkleTime = -1;
|
||||||
peer.merkleMatches = 0;
|
peer.merkleMatches = 0;
|
||||||
|
peer.merkleMap = null;
|
||||||
peer.blockTime = -1;
|
peer.blockTime = -1;
|
||||||
peer.blockMap.reset();
|
peer.blockMap.reset();
|
||||||
peer.compactBlocks.reset();
|
peer.compactBlocks.reset();
|
||||||
@ -2454,18 +2455,34 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) {
|
|||||||
var tx = packet.tx;
|
var tx = packet.tx;
|
||||||
var hash = tx.hash('hex');
|
var hash = tx.hash('hex');
|
||||||
var flags = chainCommon.flags.VERIFY_NONE;
|
var flags = chainCommon.flags.VERIFY_NONE;
|
||||||
|
var block = peer.merkleBlock;
|
||||||
var missing;
|
var missing;
|
||||||
|
|
||||||
if (peer.merkleBlock) {
|
if (block) {
|
||||||
assert(peer.merkleMatches > 0);
|
assert(peer.merkleMatches > 0);
|
||||||
if (peer.merkleBlock.hasTX(hash)) {
|
assert(peer.merkleMap);
|
||||||
peer.merkleBlock.addTX(tx);
|
|
||||||
if (--peer.merkleMatches === 0) {
|
if (block.hasTX(hash)) {
|
||||||
yield this._addBlock(peer, peer.merkleBlock, flags);
|
if (peer.merkleMap.has(hash)) {
|
||||||
peer.merkleTime = -1;
|
this.logger.warning(
|
||||||
peer.merkleBlock = null;
|
'Peer sent duplicate merkle tx: %s (%s).',
|
||||||
peer.merkleMatches = 0;
|
tx.txid(), peer.hostname());
|
||||||
|
peer.increaseBan(100);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
peer.merkleMap.insert(hash);
|
||||||
|
|
||||||
|
block.addTX(tx);
|
||||||
|
|
||||||
|
if (--peer.merkleMatches === 0) {
|
||||||
|
peer.merkleBlock = null;
|
||||||
|
peer.merkleTime = -1;
|
||||||
|
peer.merkleMatches = 0;
|
||||||
|
peer.merkleMap = null;
|
||||||
|
yield this._addBlock(peer, block, flags);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2684,9 +2701,10 @@ Pool.prototype._handleMerkleBlock = co(function* handleMerkleBlock(peer, packet)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.merkleTime = util.ms();
|
|
||||||
peer.merkleBlock = block;
|
peer.merkleBlock = block;
|
||||||
|
peer.merkleTime = util.ms();
|
||||||
peer.merkleMatches = block.tree.matches.length;
|
peer.merkleMatches = block.tree.matches.length;
|
||||||
|
peer.merkleMap = new Map();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user