use of io.nuls.consensus.event.GetBlockRequest in project nuls by nuls-io.
the class BlockBatchDownloadUtils method sendRequest.
private void sendRequest(long start, long end, String nodeId) {
NodeDownloadingStatus status = new NodeDownloadingStatus();
status.setStart(start);
status.setEnd(end);
status.setNodeId(nodeId);
this.eventBroadcaster.sendToNode(new GetBlockRequest(start, end), nodeId);
status.setUpdateTime(System.currentTimeMillis());
nodeStatusMap.put(nodeId, status);
Log.info("download block :" + start + "-" + end + ",from : " + nodeId);
}
use of io.nuls.consensus.event.GetBlockRequest in project nuls by nuls-io.
the class BlockManager method addBlock.
public void addBlock(Block block, boolean verify, String nodeId) {
if (block == null || block.getHeader() == null || block.getTxs() == null || block.getTxs().isEmpty()) {
return;
}
if (storedHeight == 0) {
BlockService blockService = NulsContext.getServiceBean(BlockService.class);
if (null != blockService) {
storedHeight = blockService.getLocalSavedHeight();
}
}
if (block.getHeader().getHeight() <= storedHeight) {
return;
}
if (verify) {
block.verifyWithException();
}
boolean success = confrimingBlockCacheManager.cacheBlock(block);
if (!success) {
blockCacheBuffer.cacheBlock(block);
boolean hasPre = blockCacheBuffer.getBlock(block.getHeader().getPreHash().getDigestHex()) != null;
if (!hasPre && null != nodeId) {
GetBlockRequest request = new GetBlockRequest();
GetBlockParam params = new GetBlockParam();
long height = block.getHeader().getHeight();
if (height > this.bifurcateProcessor.getMaxHeight()) {
height = this.bifurcateProcessor.getMaxHeight() + 1;
}
params.setStart(height);
params.setEnd(height);
request.setEventBody(params);
this.eventBroadcaster.sendToNode(request, nodeId);
}
return;
}
bifurcateProcessor.addHeader(block.getHeader());
if (bifurcateProcessor.getChainSize() == 1) {
try {
this.appravalBlock(block);
context.setBestBlock(block);
this.lastAppravedHash = block.getHeader().getHash().getDigestHex();
checkNextblock(block.getHeader().getHash().getDigestHex());
} catch (Exception e) {
confrimingBlockCacheManager.removeBlock(block.getHeader().getHash().getDigestHex());
blockCacheBuffer.cacheBlock(block);
return;
}
} else {
this.rollbackAppraval(block);
}
}
Aggregations