use of bisq.core.dao.node.parser.exceptions.BlockNotConnectingException in project bisq-core by bisq-network.
the class BlockParser method validateIfBlockIsConnecting.
private void validateIfBlockIsConnecting(RawBlock rawBlock) throws BlockNotConnectingException {
LinkedList<Block> blocks = bsqStateService.getBlocks();
if (!isBlockConnecting(rawBlock, blocks)) {
final Block last = blocks.getLast();
log.warn("addBlock called with a not connecting block. New block:\n" + "height()={}, hash()={}, lastBlock.height()={}, lastBlock.hash()={}", rawBlock.getHeight(), rawBlock.getHash(), last != null ? last.getHeight() : "null", last != null ? last.getHash() : "null");
throw new BlockNotConnectingException(rawBlock);
}
}
use of bisq.core.dao.node.parser.exceptions.BlockNotConnectingException in project bisq-core by bisq-network.
the class FullNode method addBlockHandler.
// /////////////////////////////////////////////////////////////////////////////////////////
// Private
// /////////////////////////////////////////////////////////////////////////////////////////
private void addBlockHandler() {
if (!addBlockHandlerAdded) {
addBlockHandlerAdded = true;
rpcService.addNewBtcBlockHandler(rawBlock -> {
if (!isBlockAlreadyAdded(rawBlock)) {
try {
Block block = blockParser.parseBlock(rawBlock);
onNewBlock(block);
} catch (BlockNotConnectingException throwable) {
handleError(throwable);
}
}
}, this::handleError);
}
}
use of bisq.core.dao.node.parser.exceptions.BlockNotConnectingException in project bisq-core by bisq-network.
the class FullNode method parseBlock.
// Recursively request and parse all blocks
private void parseBlock(int blockHeight, int chainHeadHeight, Consumer<Block> newBlockHandler, ResultHandler resultHandler, Consumer<Throwable> errorHandler) {
rpcService.requestBtcBlock(blockHeight, rawBlock -> {
if (!isBlockAlreadyAdded(rawBlock)) {
try {
Block block = blockParser.parseBlock(rawBlock);
newBlockHandler.accept(block);
// Increment blockHeight and recursively call parseBlockAsync until we reach chainHeadHeight
if (blockHeight < chainHeadHeight) {
final int newBlockHeight = blockHeight + 1;
parseBlock(newBlockHeight, chainHeadHeight, newBlockHandler, resultHandler, errorHandler);
} else {
// We are done
resultHandler.handleResult();
}
} catch (BlockNotConnectingException e) {
errorHandler.accept(e);
}
}
}, errorHandler);
}
Aggregations