Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Change to BlockParser.isBlockAlreadyAdded() by inverting logic
Browse files Browse the repository at this point in the history
Also add TODO about concern in validating block header vs just
block height.
  • Loading branch information
chirhonul committed Aug 20, 2018
1 parent e8b259e commit bd25b3c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/bisq/core/dao/node/parser/BlockParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public Block parseBlock(RawBlock rawBlock) throws BlockNotConnectingException {
rawBlock.getHash(),
rawBlock.getPreviousBlockHash());

if (isBlockNotAlreadyAdded(rawBlock)) {
bsqStateService.onNewBlockWithEmptyTxs(block);
} else {
if (isBlockAlreadyAdded(rawBlock)) {
//TODO check how/if that can happen
log.warn("Block was already added.");
DevEnv.logErrorAndThrowIfDevMode("Block was already added. rawBlock=" + rawBlock);
} else {
bsqStateService.onNewBlockWithEmptyTxs(block);
}

// Worst case is that all txs in a block are depending on another, so only one get resolved at each iteration.
Expand Down Expand Up @@ -134,8 +134,10 @@ private void validateIfBlockIsConnecting(RawBlock rawBlock) throws BlockNotConne
}
}

private boolean isBlockNotAlreadyAdded(RawBlock rawBlock) {
return !bsqStateService.getBlockAtHeight(rawBlock.getHeight()).isPresent();
private boolean isBlockAlreadyAdded(RawBlock rawBlock) {
// TODO(chirhonul): shouldn't we verify that we know about the blockHash, not just that the
// block heights are the same? how do we handle chainsplits otherwise?
return bsqStateService.getBlockAtHeight(rawBlock.getHeight()).isPresent();
}

private boolean isBlockConnecting(RawBlock rawBlock, LinkedList<Block> blocks) {
Expand Down

0 comments on commit bd25b3c

Please sign in to comment.