|
|
@ -37,9 +37,6 @@ import java.util.Map; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.function.Function; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class DownloadReceiptsStep |
|
|
|
public class DownloadReceiptsStep |
|
|
|
implements Function<List<Block>, CompletableFuture<List<BlockWithReceipts>>> { |
|
|
|
implements Function<List<Block>, CompletableFuture<List<BlockWithReceipts>>> { |
|
|
|
|
|
|
|
|
|
|
@ -65,18 +62,26 @@ public class DownloadReceiptsStep |
|
|
|
if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { |
|
|
|
if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { |
|
|
|
return ethContext |
|
|
|
return ethContext |
|
|
|
.getScheduler() |
|
|
|
.getScheduler() |
|
|
|
.scheduleServiceTask( |
|
|
|
.scheduleServiceTask(() -> getReceiptsWithPeerTaskSystem(headers)) |
|
|
|
() -> { |
|
|
|
.thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem) |
|
|
|
|
|
|
|
.run() |
|
|
|
|
|
|
|
.thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>> |
|
|
|
|
|
|
|
getReceiptsWithPeerTaskSystem(final List<BlockHeader> headers) { |
|
|
|
Map<BlockHeader, List<TransactionReceipt>> getReceipts = new HashMap<>(); |
|
|
|
Map<BlockHeader, List<TransactionReceipt>> getReceipts = new HashMap<>(); |
|
|
|
do { |
|
|
|
do { |
|
|
|
GetReceiptsFromPeerTask task = |
|
|
|
GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(headers, new BodyValidator()); |
|
|
|
new GetReceiptsFromPeerTask(headers, new BodyValidator()); |
|
|
|
PeerTaskExecutorResult<Map<BlockHeader, List<TransactionReceipt>>> getReceiptsResult = |
|
|
|
PeerTaskExecutorResult<Map<BlockHeader, List<TransactionReceipt>>> |
|
|
|
peerTaskExecutor.execute(task); |
|
|
|
getReceiptsResult = peerTaskExecutor.execute(task); |
|
|
|
|
|
|
|
if (getReceiptsResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS |
|
|
|
if (getReceiptsResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS |
|
|
|
&& getReceiptsResult.result().isPresent()) { |
|
|
|
&& getReceiptsResult.result().isPresent()) { |
|
|
|
Map<BlockHeader, List<TransactionReceipt>> taskResult = |
|
|
|
Map<BlockHeader, List<TransactionReceipt>> taskResult = getReceiptsResult.result().get(); |
|
|
|
getReceiptsResult.result().get(); |
|
|
|
|
|
|
|
taskResult |
|
|
|
taskResult |
|
|
|
.keySet() |
|
|
|
.keySet() |
|
|
|
.forEach( |
|
|
|
.forEach( |
|
|
@ -93,15 +98,7 @@ public class DownloadReceiptsStep |
|
|
|
headers.removeAll(getReceipts.keySet()); |
|
|
|
headers.removeAll(getReceipts.keySet()); |
|
|
|
// repeat until all headers have receipts
|
|
|
|
// repeat until all headers have receipts
|
|
|
|
} while (!headers.isEmpty()); |
|
|
|
} while (!headers.isEmpty()); |
|
|
|
return CompletableFuture.completedFuture( |
|
|
|
return CompletableFuture.completedFuture(getReceipts); |
|
|
|
combineBlocksAndReceipts(blocks, getReceipts)); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return GetReceiptsForHeadersTask.forHeaders(ethContext, headers, metricsSystem) |
|
|
|
|
|
|
|
.run() |
|
|
|
|
|
|
|
.thenApply((receipts) -> combineBlocksAndReceipts(blocks, receipts)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<BlockWithReceipts> combineBlocksAndReceipts( |
|
|
|
private List<BlockWithReceipts> combineBlocksAndReceipts( |
|
|
|