diff --git a/rskj-core/src/main/java/co/rsk/core/bc/TransactionPoolImpl.java b/rskj-core/src/main/java/co/rsk/core/bc/TransactionPoolImpl.java index 92efc0eeaee..29a28577ca4 100644 --- a/rskj-core/src/main/java/co/rsk/core/bc/TransactionPoolImpl.java +++ b/rskj-core/src/main/java/co/rsk/core/bc/TransactionPoolImpl.java @@ -153,6 +153,7 @@ public Block getBestBlock() { return bestBlock; } + @Override public void setBestBlock(Block bestBlock) { this.bestBlock = bestBlock; } diff --git a/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java b/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java index da5df5721bb..31f70f65cf6 100644 --- a/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java +++ b/rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java @@ -156,16 +156,16 @@ public void processSnapStatusRequest(Peer sender) { } public void processSnapStatusResponse(Peer sender, SnapStatusResponseMessage responseMessage) { - List blocks = responseMessage.getBlocks(); - List difficulties = responseMessage.getDifficulties(); - this.lastBlock = blocks.get(blocks.size() - 1); + List blocksFromResponse = responseMessage.getBlocks(); + List difficultiesFromResponse = responseMessage.getDifficulties(); + this.lastBlock = blocksFromResponse.get(blocksFromResponse.size() - 1); this.lastBlockDifficulty = lastBlock.getCumulativeDifficulty(); this.remoteRootHash = this.lastBlock.getStateRoot(); this.remoteTrieSize = responseMessage.getTrieSize(); - this.blocks.addAll(blocks); - this.difficulties.addAll(difficulties); + this.blocks.addAll(blocksFromResponse); + this.difficulties.addAll(difficultiesFromResponse); logger.debug("CLIENT - Processing snapshot status response - blockNumber: {} rootHash: {} triesize: {}", lastBlock.getNumber(), remoteRootHash, remoteTrieSize); - requestBlocksChunk(sender, blocks.get(0).getNumber()); + requestBlocksChunk(sender, blocksFromResponse.get(0).getNumber()); generateChunkRequestTasks(); startRequestingChunks(); } @@ -193,11 +193,11 @@ public void processSnapBlocksRequest(Peer sender, SnapBlocksRequestMessage snapB public void processSnapBlocksResponse(Peer sender, SnapBlocksResponseMessage snapBlocksResponseMessage) { logger.debug("CLIENT - Processing snap blocks response"); - List blocks = snapBlocksResponseMessage.getBlocks(); - List difficulties = snapBlocksResponseMessage.getDifficulties(); - this.blocks.addAll(blocks); - this.difficulties.addAll(difficulties); - long nextChunk = blocks.get(0).getNumber(); + List blocksFromResponse = snapBlocksResponseMessage.getBlocks(); + List difficultiesFromResponse = snapBlocksResponseMessage.getDifficulties(); + this.blocks.addAll(blocksFromResponse); + this.difficulties.addAll(difficultiesFromResponse); + long nextChunk = blocksFromResponse.get(0).getNumber(); if (nextChunk > this.lastBlock.getNumber() - BLOCKS_REQUIRED) { requestBlocksChunk(sender, nextChunk); } else { diff --git a/rskj-core/src/main/java/co/rsk/net/SyncProcessor.java b/rskj-core/src/main/java/co/rsk/net/SyncProcessor.java index ecef2fd315a..9a4847d50c3 100644 --- a/rskj-core/src/main/java/co/rsk/net/SyncProcessor.java +++ b/rskj-core/src/main/java/co/rsk/net/SyncProcessor.java @@ -280,7 +280,7 @@ public void startBlockForwardSyncing(Peer peer) { @Override public void startSnapSync(PeersInformation peers) { - logger.info("Start Snap syncing with #{} nodes", peers); + logger.info("Start Snap syncing with #{} nodes", peers.getBestPeerCandidates()); setSyncState(new SnapSyncState(this, snapshotProcessor, syncConfiguration, peers)); } diff --git a/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java b/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java index d9bc6596ee9..58a6dc815b2 100644 --- a/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java +++ b/rskj-core/src/main/java/co/rsk/net/sync/PeerAndModeDecidingSyncState.java @@ -94,7 +94,8 @@ private boolean tryStartSnapshotSync() { // TODO(snap-poc) deal with multiple peers logic here Optional bestPeerOpt = peersInformation.getBestPeer(); Optional peerBestBlockNumOpt = bestPeerOpt.flatMap(this::getPeerBestBlockNumber); - List bestPeers = peersInformation.getBestPeerCandidates(); + // TODO: To be handled when we implement the multiple peers + //List bestPeers = peersInformation.getBestPeerCandidates(); if (!bestPeerOpt.isPresent() || !peerBestBlockNumOpt.isPresent()) { logger.trace("Snap syncing not possible, no valid peer"); diff --git a/rskj-core/src/test/java/co/rsk/net/SnapshotProcessorTest.java b/rskj-core/src/test/java/co/rsk/net/SnapshotProcessorTest.java index 7c8e5c7e6fb..93579e4e54c 100644 --- a/rskj-core/src/test/java/co/rsk/net/SnapshotProcessorTest.java +++ b/rskj-core/src/test/java/co/rsk/net/SnapshotProcessorTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.*; -class SnapshotProcessorTest { +public class SnapshotProcessorTest { public static final int TEST_CHUNK_SIZE = 200; private BlockChainBuilder blockChainBuilder; private Blockchain blockchain; @@ -90,7 +90,7 @@ void givenSnapStatusResponseCalled_thenSnapChunkRequestsAreMade() { TEST_CHUNK_SIZE, false); - for (int blockNumber = 0; blockNumber < blockchain.getSize(); blockNumber ++){ + for (long blockNumber = 0; blockNumber < blockchain.getSize(); blockNumber ++){ Block currentBlock = blockchain.getBlockByNumber(blockNumber); blocks.add(currentBlock); difficulties.add(blockStore.getTotalDifficultyForHash(currentBlock.getHash().getBytes())); @@ -161,7 +161,7 @@ void givenSnapBlocksResponseReceived_thenSnapBlocksRequestMessageIsSent() { 200, false); - for (int blockNumber = 0; blockNumber < blockchain.getSize(); blockNumber ++){ + for (long blockNumber = 0; blockNumber < blockchain.getSize(); blockNumber ++){ Block currentBlock = blockchain.getBlockByNumber(blockNumber); blocks.add(currentBlock); difficulties.add(blockStore.getTotalDifficultyForHash(currentBlock.getHash().getBytes()));