Skip to content

Commit

Permalink
fix: don't watch disconnects if dropping peers after broadcast (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
HashEngineering authored Sep 7, 2023
1 parent 6422489 commit 63c08c8
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TransactionBroadcast {
private boolean dropPeersAfterBroadcast = false;
private int numWaitingFor;
/** stores a boolean value for the disconnect status of a peer during sending **/
private HashMap<PeerAddress, Boolean> sentToPeers = new HashMap<>();
private final HashMap<PeerAddress, Boolean> sentToPeers = new HashMap<>();
private int numToBroadcastTo;

/** Used for shuffling the peers before broadcast: unit tests can replace this to make themselves deterministic. */
Expand Down Expand Up @@ -98,14 +98,16 @@ public void setDropPeersAfterBroadcast(boolean dropPeersAfterBroadcast) {
}

public ListenableFuture<Transaction> broadcast() {
peerGroup.addDisconnectedEventListener(Threading.SAME_THREAD, disconnectedListener);
if (!dropPeersAfterBroadcast) {
peerGroup.addDisconnectedEventListener(Threading.SAME_THREAD, disconnectedListener);
}
log.info("Waiting for {} peers required for broadcast, we have {} ...", minConnections, peerGroup.getConnectedPeers().size());
peerGroup.waitForPeers(minConnections).addListener(new EnoughAvailablePeers(), Threading.SAME_THREAD);
return future;
}

private class EnoughAvailablePeers implements Runnable {
private Context context;
private final Context context;

public EnoughAvailablePeers() {
this.context = Context.get();
Expand Down

0 comments on commit 63c08c8

Please sign in to comment.