TransactionBroadcast: extract method dropPeerAfterBroadcastHandler(Peer)

Refactor the creation of this lambda to its own method.
This commit is contained in:
Sean Gilligan 2022-07-30 21:56:38 -07:00 committed by Andreas Schildbach
parent 81fd758800
commit 419dba9845

View file

@ -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