diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNode.java b/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNode.java index 4572938e45d..411fe17afe2 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNode.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNode.java @@ -64,11 +64,15 @@ public static Sha256Hash getSha256Hash(AccountingBlock block) { @Nullable public static Sha256Hash getSha256Hash(Collection blocks) { + long ts = System.currentTimeMillis(); try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { for (AccountingBlock accountingBlock : blocks) { outputStream.write(accountingBlock.toProtoMessage().toByteArray()); } - return Sha256Hash.of(outputStream.toByteArray()); + Sha256Hash hash = Sha256Hash.of(outputStream.toByteArray()); + // 2833 blocks takes about 23 ms + log.info("getSha256Hash for {} blocks took {} ms", blocks.size(), System.currentTimeMillis() - ts); + return hash; } catch (IOException e) { return null; } diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/node/lite/AccountingLiteNode.java b/core/src/main/java/bisq/core/dao/burningman/accounting/node/lite/AccountingLiteNode.java index d6c437682c8..19ba34481d0 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/node/lite/AccountingLiteNode.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/node/lite/AccountingLiteNode.java @@ -48,6 +48,8 @@ import java.util.Comparator; import java.util.List; import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicBoolean; import lombok.extern.slf4j.Slf4j; @@ -191,35 +193,44 @@ protected void applyReOrg() { /////////////////////////////////////////////////////////////////////////////////////////// private void processAccountingBlocks(List blocks) { - log.info("We received blocks from height {} to {}", - blocks.get(0).getHeight(), - blocks.get(blocks.size() - 1).getHeight()); - - boolean requiresReOrg = false; - for (AccountingBlock block : blocks) { - try { - burningManAccountingService.addBlock(block); - } catch (BlockHeightNotConnectingException e) { - log.info("Height not connecting. This could happen if we received multiple responses and had already applied a previous one. {}", e.toString()); - } catch (BlockHashNotConnectingException e) { - log.warn("Interrupt loop because a reorg is required. {}", e.toString()); - requiresReOrg = true; - break; + CompletableFuture.runAsync(() -> { + long ts = System.currentTimeMillis(); + log.info("We received blocks from height {} to {}", + blocks.get(0).getHeight(), + blocks.get(blocks.size() - 1).getHeight()); + + AtomicBoolean requiresReOrg = new AtomicBoolean(false); + for (AccountingBlock block : blocks) { + try { + burningManAccountingService.addBlock(block); + } catch (BlockHeightNotConnectingException e) { + log.info("Height not connecting. This could happen if we received multiple responses and had already applied a previous one. {}", e.toString()); + } catch (BlockHashNotConnectingException e) { + log.warn("Interrupt loop because a reorg is required. {}", e.toString()); + requiresReOrg.set(true); + break; + } } - } - if (requiresReOrg) { - applyReOrg(); - return; - } - int heightOfLastBlock = burningManAccountingService.getBlockHeightOfLastBlock(); - if (walletsSetup.isDownloadComplete() && heightOfLastBlock < bsqWalletService.getBestChainHeight()) { - accountingLiteNodeNetworkService.requestBlocks(heightOfLastBlock + 1); - } else { - if (!initialBlockRequestsComplete) { - onInitialBlockRequestsComplete(); - } - } + UserThread.execute(() -> { + if (requiresReOrg.get()) { + applyReOrg(); + return; + } + + int heightOfLastBlock = burningManAccountingService.getBlockHeightOfLastBlock(); + if (walletsSetup.isDownloadComplete() && heightOfLastBlock < bsqWalletService.getBestChainHeight()) { + accountingLiteNodeNetworkService.requestBlocks(heightOfLastBlock + 1); + } else { + if (!initialBlockRequestsComplete) { + onInitialBlockRequestsComplete(); + } + } + + // 2833 blocks takes about 24 sec + log.info("processAccountingBlocksAsync for {} blocks took {} ms", blocks.size(), System.currentTimeMillis() - ts); + }); + }); } private void processNewAccountingBlock(AccountingBlock accountingBlock) {