Search in sources :

Example 1 with BsqBlock

use of bisq.core.dao.blockchain.vo.BsqBlock in project bisq-core by bisq-network.

the class LiteNodeParser method parseBsqBlocks.

void parseBsqBlocks(List<BsqBlock> bsqBlocks, Consumer<BsqBlock> newBlockHandler) throws BlockNotConnectingException {
    for (BsqBlock bsqBlock : bsqBlocks) {
        parseBsqBlock(bsqBlock);
        newBlockHandler.accept(bsqBlock);
    }
}
Also used : BsqBlock(bisq.core.dao.blockchain.vo.BsqBlock)

Example 2 with BsqBlock

use of bisq.core.dao.blockchain.vo.BsqBlock in project bisq-core by bisq-network.

the class FullNodeParser method parseBlock.

BsqBlock parseBlock(Block btcdBlock) throws BsqBlockchainException, BlockNotConnectingException {
    long startTs = System.currentTimeMillis();
    List<Tx> bsqTxsInBlock = findBsqTxsInBlock(btcdBlock);
    final BsqBlock bsqBlock = new BsqBlock(btcdBlock.getHeight(), btcdBlock.getTime(), btcdBlock.getHash(), btcdBlock.getPreviousBlockHash(), ImmutableList.copyOf(bsqTxsInBlock));
    bsqBlockController.addBlockIfValid(bsqBlock);
    log.debug("parseBlock took {} ms at blockHeight {}; bsqTxsInBlock.size={}", System.currentTimeMillis() - startTs, bsqBlock.getHeight(), bsqTxsInBlock.size());
    return bsqBlock;
}
Also used : Tx(bisq.core.dao.blockchain.vo.Tx) BsqBlock(bisq.core.dao.blockchain.vo.BsqBlock)

Example 3 with BsqBlock

use of bisq.core.dao.blockchain.vo.BsqBlock in project bisq-core by bisq-network.

the class FullNodeParser method parseBlocks.

// /////////////////////////////////////////////////////////////////////////////////////////
// Package private
// /////////////////////////////////////////////////////////////////////////////////////////
@VisibleForTesting
void parseBlocks(int startBlockHeight, int chainHeadHeight, Consumer<BsqBlock> newBlockHandler) throws BsqBlockchainException, BlockNotConnectingException {
    try {
        for (int blockHeight = startBlockHeight; blockHeight <= chainHeadHeight; blockHeight++) {
            Block btcdBlock = rpcService.requestBlock(blockHeight);
            final BsqBlock bsqBlock = parseBlock(btcdBlock);
            newBlockHandler.accept(bsqBlock);
        }
    } catch (BlockNotConnectingException e) {
        throw e;
    } catch (Throwable t) {
        log.error(t.toString());
        t.printStackTrace();
        throw new BsqBlockchainException(t);
    }
}
Also used : BsqBlockchainException(bisq.core.dao.blockchain.exceptions.BsqBlockchainException) BsqBlock(bisq.core.dao.blockchain.vo.BsqBlock) Block(com.neemre.btcdcli4j.core.domain.Block) BlockNotConnectingException(bisq.core.dao.blockchain.exceptions.BlockNotConnectingException) BsqBlock(bisq.core.dao.blockchain.vo.BsqBlock) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with BsqBlock

use of bisq.core.dao.blockchain.vo.BsqBlock in project bisq-core by bisq-network.

the class GetBsqBlocksRequestHandler method onGetBsqBlocksRequest.

// /////////////////////////////////////////////////////////////////////////////////////////
// API
// /////////////////////////////////////////////////////////////////////////////////////////
public void onGetBsqBlocksRequest(GetBsqBlocksRequest getBsqBlocksRequest, final Connection connection) {
    Log.traceCall(getBsqBlocksRequest + "\n\tconnection=" + connection);
    List<BsqBlock> bsqBlocks = readableBsqBlockChain.getClonedBlocksFrom(getBsqBlocksRequest.getFromBlockHeight());
    final GetBsqBlocksResponse bsqBlocksResponse = new GetBsqBlocksResponse(bsqBlocks, getBsqBlocksRequest.getNonce());
    log.debug("bsqBlocksResponse " + bsqBlocksResponse.getRequestNonce());
    if (timeoutTimer == null) {
        timeoutTimer = UserThread.runAfter(() -> {
            // setup before sending to avoid race conditions
            String errorMessage = "A timeout occurred for bsqBlocksResponse:" + bsqBlocksResponse + " on connection:" + connection;
            handleFault(errorMessage, CloseConnectionReason.SEND_MSG_TIMEOUT, connection);
        }, TIMEOUT, TimeUnit.SECONDS);
    }
    SettableFuture<Connection> future = networkNode.sendMessage(connection, bsqBlocksResponse);
    Futures.addCallback(future, new FutureCallback<Connection>() {

        @Override
        public void onSuccess(Connection connection) {
            if (!stopped) {
                log.trace("Send DataResponse to {} succeeded. bsqBlocksResponse={}", connection.getPeersNodeAddressOptional(), bsqBlocksResponse);
                cleanup();
                listener.onComplete();
            } else {
                log.trace("We have stopped already. We ignore that networkNode.sendMessage.onSuccess call.");
            }
        }

        @Override
        public void onFailure(@NotNull Throwable throwable) {
            if (!stopped) {
                String errorMessage = "Sending bsqBlocksResponse to " + connection + " failed. That is expected if the peer is offline. bsqBlocksResponse=" + bsqBlocksResponse + "." + "Exception: " + throwable.getMessage();
                handleFault(errorMessage, CloseConnectionReason.SEND_MSG_FAILURE, connection);
            } else {
                log.trace("We have stopped already. We ignore that networkNode.sendMessage.onFailure call.");
            }
        }
    });
}
Also used : Connection(bisq.network.p2p.network.Connection) GetBsqBlocksResponse(bisq.core.dao.node.messages.GetBsqBlocksResponse) BsqBlock(bisq.core.dao.blockchain.vo.BsqBlock)

Aggregations

BsqBlock (bisq.core.dao.blockchain.vo.BsqBlock)4 BlockNotConnectingException (bisq.core.dao.blockchain.exceptions.BlockNotConnectingException)1 BsqBlockchainException (bisq.core.dao.blockchain.exceptions.BsqBlockchainException)1 Tx (bisq.core.dao.blockchain.vo.Tx)1 GetBsqBlocksResponse (bisq.core.dao.node.messages.GetBsqBlocksResponse)1 Connection (bisq.network.p2p.network.Connection)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Block (com.neemre.btcdcli4j.core.domain.Block)1