Search in sources :

Example 1 with BlockNotConnectingException

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);
    }
}
Also used : RawBlock(bisq.core.dao.state.blockchain.RawBlock) Block(bisq.core.dao.state.blockchain.Block) BlockNotConnectingException(bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)

Example 2 with BlockNotConnectingException

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);
    }
}
Also used : Block(bisq.core.dao.state.blockchain.Block) BlockNotConnectingException(bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)

Example 3 with BlockNotConnectingException

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);
}
Also used : Block(bisq.core.dao.state.blockchain.Block) BlockNotConnectingException(bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)

Aggregations

BlockNotConnectingException (bisq.core.dao.node.parser.exceptions.BlockNotConnectingException)3 Block (bisq.core.dao.state.blockchain.Block)3 RawBlock (bisq.core.dao.state.blockchain.RawBlock)1