TransactionBroadcast: extract method dropPeerAfterBroadcastHandler(Peer)
Refactor the creation of this lambda to its own method.
@@ -212,10 +212,7 @@ public class TransactionBroadcast {
if (dropPeersAfterBroadcast) {
// We drop the peer shortly after the transaction has been sent, because this peer will not
// send us back useful broadcast confirmations.
- future.thenRunAsync(() -> {
- Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
- peer.close();
- }, Threading.THREAD_POOL);
+ future.thenRunAsync(dropPeerAfterBroadcastHandler(peer), Threading.THREAD_POOL);
}
// We don't record the peer as having seen the tx in the memory pool because we want to track only
// how many peers announced to us.
@@ -226,6 +223,13 @@ public class TransactionBroadcast {
}
}
+ private static Runnable dropPeerAfterBroadcastHandler(Peer peer) {
+ return () -> {
+ Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
+ peer.close();
+ };
+ }
+
/**
* Randomly choose a subset of connected peers to broadcast to
* @param connectedPeers connected peers to chose from
