use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class AssemblyBlockUtil method assemblyBlock.
public static Block assemblyBlock(BlockHeader header, Map<NulsDigestData, Transaction> txMap, List<NulsDigestData> txHashList) {
Block block = new Block();
block.setHeader(header);
List<Transaction> txs = new ArrayList<>();
for (NulsDigestData txHash : txHashList) {
Transaction tx = txMap.get(txHash);
if (null == tx) {
throw new NulsRuntimeException(TransactionErrorCode.TX_NOT_EXIST);
}
tx.setBlockHeight(header.getHeight());
txs.add(tx);
}
block.setTxs(txs);
return block;
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class DownloadThreadManager method checkFirstBlock.
private boolean checkFirstBlock() throws NulsException {
Block localBestBlock = blockService.getBestBlock().getData();
if (localBestBlock.getHeader().getHeight() == 0 || (newestInfos.getNetBestHeight() == localBestBlock.getHeader().getHeight() && newestInfos.getNetBestHash().equals(localBestBlock.getHeader().getHash()))) {
return true;
}
if (newestInfos.getNetBestHeight() < localBestBlock.getHeader().getHeight()) {
BlockHeader header = blockService.getBlockHeader(newestInfos.getNetBestHash()).getData();
if (null == header && networkService.getAvailableNodes().size() >= networkService.getNetworkParam().getMaxOutCount() && DoubleUtils.div(newestInfos.getNodes().size(), networkService.getAvailableNodes().size(), 2) >= 0.5d) {
for (long i = localBestBlock.getHeader().getHeight(); i <= newestInfos.getNetBestHeight(); i--) {
consensusService.rollbackBlock(localBestBlock);
localBestBlock = blockService.getBestBlock().getData();
}
} else if (null == header) {
resetNetwork("The local block is higher than the network block, the number of connected nodes is not enough to allow the local rollbackTx, so reset");
return false;
}
} else {
// check need rollbackTx
return checkRollback(localBestBlock, 0);
}
return true;
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class BlockMessageHandler method onMessage.
@Override
public void onMessage(BlockMessage event, Node fromNode) {
Block block = event.getMsgBody();
if (null == block) {
Log.warn("recieved a null blockEvent form " + fromNode.getId());
return;
}
// Log.info("recieved:::::" + block.getHeader().getHeight() + ":::::" + fromNode.getId());
boolean result = CollectThread.getInstance().addBlock(block);
if (result) {
return;
}
ProtocolCacheHandler.receiveBlock(block);
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class CollectThread method waitBlock.
private Block waitBlock(long height) throws InterruptedException {
Block block = null;
long totalWait = 0;
while (null == block && height == startHeight) {
Thread.sleep(10L);
totalWait += 10;
if (totalWait > 5000) {
boolean b = this.requestThread.retryDownload(height, getRequestSize());
if (!b) {
break;
}
// Log.info("Height:" + height + ",累计等待时间ms:::::" + totalWait+" , map size:"+map.size());
totalWait = 0;
}
block = map.remove(startHeight);
}
// Log.info("Height:" + height + ",累计等待时间ms:::::" + totalWait+" , map size:"+map.size());
return block;
}
Aggregations