3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-30 23:02:15 +00:00

Run TransactionConfidence listeners with the confidence object unlocked when markBroadcastBy is called. Resolves issue 270.

This commit is contained in:
Mike Hearn 2013-01-07 11:13:33 +01:00
parent ae6b2fbd4d
commit ee5f881c51

View File

@ -79,15 +79,14 @@ public class TransactionConfidence implements Serializable {
*/ */
private BigInteger workDone = BigInteger.ZERO; private BigInteger workDone = BigInteger.ZERO;
// TODO: The advice below is a mess. There should be block chain listeners, see issue 94.
/** /**
* <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * <p>Adds an event listener that will be run when this confidence object is updated. The listener will be locked and
* is likely to be invoked on a peer thread.</p> * is likely to be invoked on a peer thread.</p>
* *
* <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction * <p>Note that this is NOT called when every block arrives. Instead it is called when the transaction
* transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in
* the best chain). If you want to know when the transaction gets buried under another block, listen for new block * the best chain). If you want to know when the transaction gets buried under another block, implement a
* events using {@link PeerEventListener#onBlocksDownloaded(Peer, Block, int)} and then use the getters on the * {@link BlockChainListener}, attach it to a {@link BlockChain} and then use the getters on the
* confidence object to determine the new depth.</p> * confidence object to determine the new depth.</p>
*/ */
public synchronized void addEventListener(Listener listener) { public synchronized void addEventListener(Listener listener) {
@ -234,14 +233,14 @@ public class TransactionConfidence implements Serializable {
* *
* @param address IP address of the peer, used as a proxy for identity. * @param address IP address of the peer, used as a proxy for identity.
*/ */
public synchronized void markBroadcastBy(PeerAddress address) { public void markBroadcastBy(PeerAddress address) {
broadcastBy.add(address); synchronized (this) {
if (getConfidenceType() == ConfidenceType.UNKNOWN) { broadcastBy.add(address);
setConfidenceType(ConfidenceType.NOT_SEEN_IN_CHAIN); if (getConfidenceType() == ConfidenceType.UNKNOWN) {
// Listeners are already run by setConfidenceType. this.confidenceType = ConfidenceType.NOT_SEEN_IN_CHAIN;
} else { }
runListeners();
} }
runListeners();
} }
/** /**