Peer: construct getdata a little bit more functionally and atomically in downloadDependencies()
Build GetDataMessage in a private method.
@@ -812,11 +812,10 @@ public class Peer extends PeerSocketHandler {
try {
// Build the request for the missing dependencies.
List<CompletableFuture<Transaction>> futures = new ArrayList<>();
- GetDataMessage getdata = new GetDataMessage(params);
+ GetDataMessage getdata = buildMultiTransactionDataMessage(txIdsToRequest);
if (txIdsToRequest.size() > 1)
log.info("{}: Requesting {} transactions for depth {} dep resolution", getAddress(), txIdsToRequest.size(), depth + 1);
for (Sha256Hash hash : txIdsToRequest) {
- getdata.addTransaction(hash, vPeerVersionMessage.isWitnessSupported());
GetDataRequest req = new GetDataRequest(hash);
futures.add(req.future);
getDataFutures.add(req);
@@ -870,6 +869,18 @@ public class Peer extends PeerSocketHandler {
return resultFuture;
}
+ /**
+ * Build a GetDataMessage to query multiple transactions by ID
+ * @param txIds A set of transaction IDs to query
+ * @return A GetDataMessage that will query those IDs
+ */
+ private GetDataMessage buildMultiTransactionDataMessage(Set<Sha256Hash> txIds) {
+ GetDataMessage getdata = new GetDataMessage(params);
+ txIds.forEach(txId ->
+ getdata.addTransaction(txId, vPeerVersionMessage.isWitnessSupported()));
+ return getdata;
+ }
+
/**
* Combine the direct results and the child dependencies. Make sure to filter out nulls from
* {@code Futures.successfulAsList}.
