mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-19 13:45:48 +00:00
Fix a thread safety issue. Update issue 353.
This commit is contained in:
parent
e5265a5342
commit
8b437eaf95
@ -168,6 +168,7 @@ public class MemoryPool {
|
|||||||
* @return An object that is semantically the same TX but may be a different object instance.
|
* @return An object that is semantically the same TX but may be a different object instance.
|
||||||
*/
|
*/
|
||||||
public Transaction seen(Transaction tx, PeerAddress byPeer) {
|
public Transaction seen(Transaction tx, PeerAddress byPeer) {
|
||||||
|
boolean skipUnlock = false;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
cleanPool();
|
cleanPool();
|
||||||
@ -197,19 +198,17 @@ public class MemoryPool {
|
|||||||
// We received a transaction that we have previously seen announced but not downloaded until now.
|
// We received a transaction that we have previously seen announced but not downloaded until now.
|
||||||
checkNotNull(entry.addresses);
|
checkNotNull(entry.addresses);
|
||||||
entry.tx = new WeakTransactionReference(tx, referenceQueue);
|
entry.tx = new WeakTransactionReference(tx, referenceQueue);
|
||||||
|
Set<PeerAddress> addrs = entry.addresses;
|
||||||
|
entry.addresses = null;
|
||||||
// Copy the previously announced peers into the confidence and then clear it out. Unlock here
|
// Copy the previously announced peers into the confidence and then clear it out. Unlock here
|
||||||
// because markBroadcastBy can trigger event listeners and thus inversions.
|
// because markBroadcastBy can trigger event listeners and thus inversions.
|
||||||
|
TransactionConfidence confidence = tx.getConfidence();
|
||||||
|
log.debug("{}: Adding tx [{}] {} to the memory pool",
|
||||||
|
new Object[]{byPeer, confidence.numBroadcastPeers(), tx.getHashAsString()});
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
try {
|
skipUnlock = true;
|
||||||
TransactionConfidence confidence = tx.getConfidence();
|
for (PeerAddress a : addrs) {
|
||||||
for (PeerAddress a : entry.addresses) {
|
confidence.markBroadcastBy(a);
|
||||||
confidence.markBroadcastBy(a);
|
|
||||||
}
|
|
||||||
entry.addresses = null;
|
|
||||||
log.debug("{}: Adding tx [{}] {} to the memory pool",
|
|
||||||
new Object[]{byPeer, confidence.numBroadcastPeers(), tx.getHashAsString()});
|
|
||||||
} finally {
|
|
||||||
lock.lock();
|
|
||||||
}
|
}
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
@ -225,7 +224,7 @@ public class MemoryPool {
|
|||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
if (!skipUnlock) lock.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user