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);
}
}
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;
}
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);
}
}
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.");
}
}
});
}
Aggregations