use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.
the class ChainManager method checkIsBeforeOrphanChainAndAdd.
public boolean checkIsBeforeOrphanChainAndAdd(Block block) {
BlockHeader header = block.getHeader();
boolean success = false;
for (ChainContainer chainContainer : orphanChains) {
Chain chain = chainContainer.getChain();
if (header.getHash().equals(chain.getStartBlockHeader().getPreHash())) {
success = true;
chain.addPreBlock(block);
}
}
return success;
}
use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.
the class PoConvertUtil method fromBlockHeaderPo.
public static BlockHeader fromBlockHeaderPo(BlockHeaderPo po) {
BlockHeader header = new BlockHeader();
header.setHash(po.getHash());
header.setHeight(po.getHeight());
header.setExtend(po.getExtend());
header.setPreHash(po.getPreHash());
header.setTime(po.getTime());
header.setMerkleHash(po.getMerkleHash());
header.setTxCount(po.getTxCount());
header.setBlockSignature(po.getScriptSign());
// pierre add contract stateRoot
header.setStateRoot(po.getStateRoot());
return header;
}
use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.
the class SmallBlock method parse.
@Override
public void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.header = byteBuffer.readNulsData(new BlockHeader());
this.txHashList = new ArrayList<>();
long hashListSize = byteBuffer.readVarInt();
for (int i = 0; i < hashListSize; i++) {
this.txHashList.add(byteBuffer.readHash());
}
this.subTxList = new ArrayList<>();
long subTxListSize = byteBuffer.readVarInt();
for (int i = 0; i < subTxListSize; i++) {
Transaction tx = byteBuffer.readTransaction();
tx.setBlockHeight(header.getHeight());
this.subTxList.add(tx);
}
}
use of io.nuls.kernel.model.BlockHeader 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.BlockHeader in project nuls by nuls-io.
the class GetBlocksHashHandler method onMessage.
@Override
public void onMessage(GetBlocksHashMessage message, Node fromNode) {
GetBlocksHashParam param = message.getMsgBody();
if (param.getEndHeight() - param.getStartHeight() >= MAX_SIZE) {
return;
}
NulsDigestData requestHash = message.getHash();
BlockHeader endHeader = blockService.getBlockHeader(param.getEndHeight()).getData();
if (null == endHeader) {
sendNotFound(fromNode, requestHash);
return;
}
BlockHashResponse response = new BlockHashResponse();
response.setRequestMessageHash(requestHash);
BlockHeader header = endHeader;
while (header.getHeight() >= param.getStartHeight()) {
response.putFront(header.getHash());
header = blockService.getBlockHeader(header.getPreHash()).getData();
if (header == null) {
break;
}
}
sendResponse(response, fromNode);
}
Aggregations