Search in sources :

Example 36 with BlockHeader

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;
}
Also used : Chain(io.nuls.consensus.poc.model.Chain) ChainContainer(io.nuls.consensus.poc.container.ChainContainer) BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 37 with BlockHeader

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;
}
Also used : BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 38 with BlockHeader

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);
    }
}
Also used : Transaction(io.nuls.kernel.model.Transaction) BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 39 with BlockHeader

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;
}
Also used : Block(io.nuls.kernel.model.Block) BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 40 with BlockHeader

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);
}
Also used : GetBlocksHashParam(io.nuls.protocol.model.GetBlocksHashParam) BlockHashResponse(io.nuls.protocol.model.BlockHashResponse) NulsDigestData(io.nuls.kernel.model.NulsDigestData) BlockHeader(io.nuls.kernel.model.BlockHeader)

Aggregations

BlockHeader (io.nuls.kernel.model.BlockHeader)40 Block (io.nuls.kernel.model.Block)8 BlockExtendsData (io.nuls.consensus.poc.model.BlockExtendsData)7 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)7 NulsDigestData (io.nuls.kernel.model.NulsDigestData)7 ArrayList (java.util.ArrayList)7 PunishLogPo (io.nuls.consensus.poc.storage.po.PunishLogPo)5 Result (io.nuls.kernel.model.Result)5 ValidateResult (io.nuls.kernel.validate.ValidateResult)4 IOException (java.io.IOException)4 ChainContainer (io.nuls.consensus.poc.container.ChainContainer)3 Agent (io.nuls.consensus.poc.protocol.entity.Agent)3 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)3 ProtocolContainer (io.nuls.protocol.base.version.ProtocolContainer)3 Chain (io.nuls.consensus.poc.model.Chain)2 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)2 YellowPunishData (io.nuls.consensus.poc.protocol.entity.YellowPunishData)2 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)2 ContractResult (io.nuls.contract.dto.ContractResult)2 BlockHeaderDto (io.nuls.contract.entity.BlockHeaderDto)2