diff --git a/core/src/main/java/bisq/core/dao/node/BsqNode.java b/core/src/main/java/bisq/core/dao/node/BsqNode.java index bfad9debe13..d0168beafed 100644 --- a/core/src/main/java/bisq/core/dao/node/BsqNode.java +++ b/core/src/main/java/bisq/core/dao/node/BsqNode.java @@ -239,7 +239,9 @@ protected Optional doParseBlock(RawBlock rawBlock) throws RequiredReorgFr // We take only first element after sorting (so it is the block with the next height) to avoid that // we would repeat calls in recursions in case we would iterate the list. pendingBlocks.sort(Comparator.comparing(RawBlock::getHeight)); - doParseBlock(pendingBlocks.get(0)); + RawBlock nextPending = pendingBlocks.get(0); + if (nextPending.getHeight() == daoStateService.getChainHeight() + 1) + doParseBlock(nextPending); } return Optional.of(block); diff --git a/core/src/main/java/bisq/core/dao/node/lite/LiteNode.java b/core/src/main/java/bisq/core/dao/node/lite/LiteNode.java index 65ca2550cdb..9fd0511957b 100644 --- a/core/src/main/java/bisq/core/dao/node/lite/LiteNode.java +++ b/core/src/main/java/bisq/core/dao/node/lite/LiteNode.java @@ -131,8 +131,9 @@ protected void onP2PNetworkReady() { liteNodeNetworkService.addListener(new LiteNodeNetworkService.Listener() { @Override - public void onRequestedBlocksReceived(GetBlocksResponse getBlocksResponse) { - LiteNode.this.onRequestedBlocksReceived(new ArrayList<>(getBlocksResponse.getBlocks())); + public void onRequestedBlocksReceived(GetBlocksResponse getBlocksResponse, Runnable onParsingComplete) { + LiteNode.this.onRequestedBlocksReceived(new ArrayList<>(getBlocksResponse.getBlocks()), + onParsingComplete); } @Override @@ -175,7 +176,7 @@ protected void startReOrgFromLastSnapshot() { /////////////////////////////////////////////////////////////////////////////////////////// // We received the missing blocks - private void onRequestedBlocksReceived(List blockList) { + private void onRequestedBlocksReceived(List blockList, Runnable onParsingComplete) { if (!blockList.isEmpty()) { chainTipHeight = blockList.get(blockList.size() - 1).getHeight(); log.info("We received blocks from height {} to {}", blockList.get(0).getHeight(), chainTipHeight); @@ -199,7 +200,11 @@ private void onRequestedBlocksReceived(List blockList) { runDelayedBatchProcessing(new ArrayList<>(blockList), () -> { log.info("Parsing {} blocks took {} seconds.", blockList.size(), (System.currentTimeMillis() - ts) / 1000d); - onParseBlockChainComplete(); + if (daoStateService.getChainHeight() < bsqWalletService.getBestChainHeight()) + liteNodeNetworkService.requestBlocks(getStartBlockHeight()); + else + onParsingComplete.run(); + onParseBlockChainComplete(); }); } diff --git a/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java b/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java index f910d6c85aa..7b5c345d7fa 100644 --- a/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java +++ b/core/src/main/java/bisq/core/dao/node/lite/network/LiteNodeNetworkService.java @@ -76,7 +76,7 @@ public class LiteNodeNetworkService implements MessageListener, ConnectionListen public interface Listener { void onNoSeedNodeAvailable(); - void onRequestedBlocksReceived(GetBlocksResponse getBlocksResponse); + void onRequestedBlocksReceived(GetBlocksResponse getBlocksResponse, Runnable onParsingComplete); void onNewBlockReceived(NewBlockBroadcastMessage newBlockBroadcastMessage); @@ -269,11 +269,12 @@ public void onComplete(GetBlocksResponse getBlocksResponse) { if (startBlockHeight >= lastReceivedBlockHeight) { lastReceivedBlockHeight = startBlockHeight; - // After we received the blocks we allow to disconnect seed nodes. - // We delay 20 seconds to allow multiple requests to finish. - UserThread.runAfter(() -> peerManager.setAllowDisconnectSeedNodes(true), 20); - - listeners.forEach(listener -> listener.onRequestedBlocksReceived(getBlocksResponse)); + listeners.forEach(listener -> listener.onRequestedBlocksReceived(getBlocksResponse, + () -> { + // After we received the blocks we allow to disconnect seed nodes. + // We delay 20 seconds to allow multiple requests to finish. + UserThread.runAfter(() -> peerManager.setAllowDisconnectSeedNodes(true), 20); + })); } else { log.warn("We got a response which is already obsolete because we receive a " + "response from a request with a higher block height. " +