Skip to content

Commit

Permalink
Solving some CodeQL issues from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fmacleal committed Mar 21, 2024
1 parent 36e5af6 commit fdda355
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public Block getBestBlock() {
return bestBlock;
}

@Override
public void setBestBlock(Block bestBlock) {
this.bestBlock = bestBlock;
}
Expand Down
22 changes: 11 additions & 11 deletions rskj-core/src/main/java/co/rsk/net/SnapshotProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ public void processSnapStatusRequest(Peer sender) {
}

public void processSnapStatusResponse(Peer sender, SnapStatusResponseMessage responseMessage) {
List<Block> blocks = responseMessage.getBlocks();
List<BlockDifficulty> difficulties = responseMessage.getDifficulties();
this.lastBlock = blocks.get(blocks.size() - 1);
List<Block> blocksFromResponse = responseMessage.getBlocks();
List<BlockDifficulty> 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();
}
Expand Down Expand Up @@ -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<Block> blocks = snapBlocksResponseMessage.getBlocks();
List<BlockDifficulty> difficulties = snapBlocksResponseMessage.getDifficulties();
this.blocks.addAll(blocks);
this.difficulties.addAll(difficulties);
long nextChunk = blocks.get(0).getNumber();
List<Block> blocksFromResponse = snapBlocksResponseMessage.getBlocks();
List<BlockDifficulty> 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 {
Expand Down
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/net/SyncProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ private boolean tryStartSnapshotSync() {
// TODO(snap-poc) deal with multiple peers logic here
Optional<Peer> bestPeerOpt = peersInformation.getBestPeer();
Optional<Long> peerBestBlockNumOpt = bestPeerOpt.flatMap(this::getPeerBestBlockNumber);
List<Peer> bestPeers = peersInformation.getBestPeerCandidates();
// TODO: To be handled when we implement the multiple peers
//List<Peer> bestPeers = peersInformation.getBestPeerCandidates();

if (!bestPeerOpt.isPresent() || !peerBestBlockNumOpt.isPresent()) {
logger.trace("Snap syncing not possible, no valid peer");
Expand Down
6 changes: 3 additions & 3 deletions rskj-core/src/test/java/co/rsk/net/SnapshotProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit fdda355

Please sign in to comment.