Search in sources :

Example 11 with BlockHeader

use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.

the class CacheLoader method loadYellowPunishList.

public List<PunishLogPo> loadYellowPunishList(List<PunishLogPo> allPunishList, int roundSize) {
    List<PunishLogPo> list = new ArrayList<>();
    BlockHeader blockHeader = blockService.getBestBlockHeader().getData();
    if (null == blockHeader) {
        return list;
    }
    BlockExtendsData roundData = new BlockExtendsData(blockHeader.getExtend());
    long breakRoundIndex = roundData.getRoundIndex() - roundSize;
    for (PunishLogPo po : allPunishList) {
        if (po.getType() == PunishType.RED.getCode()) {
            continue;
        }
        if (po.getRoundIndex() <= breakRoundIndex) {
            continue;
        }
        list.add(po);
    }
    Collections.sort(list, new PunishLogComparator());
    return list;
}
Also used : BlockExtendsData(io.nuls.consensus.poc.model.BlockExtendsData) PunishLogComparator(io.nuls.consensus.poc.storage.utils.PunishLogComparator) ArrayList(java.util.ArrayList) BlockHeader(io.nuls.kernel.model.BlockHeader) PunishLogPo(io.nuls.consensus.poc.storage.po.PunishLogPo)

Example 12 with BlockHeader

use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.

the class CacheLoader method loadBlockHeaders.

/**
 * @param size
 * @return
 */
public List<BlockHeader> loadBlockHeaders(int size) {
    List<BlockHeader> blockHeaderList = new ArrayList<>();
    BlockHeader blockHeader = blockService.getBestBlockHeader().getData();
    if (null == blockHeader) {
        return blockHeaderList;
    }
    BlockExtendsData roundData = new BlockExtendsData(blockHeader.getExtend());
    long breakRoundIndex = roundData.getRoundIndex() - size;
    while (true) {
        if (blockHeader == null) {
            break;
        }
        blockHeaderList.add(0, blockHeader);
        if (blockHeader.getHeight() == 0L) {
            break;
        }
        NulsDigestData preHash = blockHeader.getPreHash();
        blockHeader = blockService.getBlockHeader(preHash).getData();
        BlockExtendsData blockRoundData = new BlockExtendsData(blockHeader.getExtend());
        if (blockRoundData.getRoundIndex() <= breakRoundIndex) {
            break;
        }
    }
    return blockHeaderList;
}
Also used : BlockExtendsData(io.nuls.consensus.poc.model.BlockExtendsData) ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.kernel.model.NulsDigestData) BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 13 with BlockHeader

use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.

the class RoundManager method getNextRoundByNotRealTime.

private MeetingRound getNextRoundByNotRealTime() {
    BlockHeader bestBlockHeader = chain.getEndBlockHeader();
    BlockExtendsData extendsData = new BlockExtendsData(bestBlockHeader.getExtend());
    extendsData.setRoundStartTime(extendsData.getRoundEndTime());
    extendsData.setRoundIndex(extendsData.getRoundIndex() + 1);
    return getNextRoundByExpectedRound(extendsData);
}
Also used : BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 14 with BlockHeader

use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.

the class RoundManager method getNextRoudByRealTime.

private MeetingRound getNextRoudByRealTime() {
    BlockHeader bestBlockHeader = chain.getEndBlockHeader();
    BlockHeader startBlockHeader = bestBlockHeader;
    BlockExtendsData bestRoundData = new BlockExtendsData(bestBlockHeader.getExtend());
    if (startBlockHeader.getHeight() != 0L) {
        long roundIndex = bestRoundData.getRoundIndex();
        if (bestRoundData.getConsensusMemberCount() == bestRoundData.getPackingIndexOfRound() || TimeService.currentTimeMillis() >= bestRoundData.getRoundEndTime()) {
            roundIndex += 1;
        }
        startBlockHeader = getFirstBlockHeightOfPreRoundByRoundIndex(roundIndex);
    }
    long nowTime = TimeService.currentTimeMillis();
    long index = 0L;
    long startTime = 0L;
    if (nowTime < bestRoundData.getRoundEndTime()) {
        index = bestRoundData.getRoundIndex();
        startTime = bestRoundData.getRoundStartTime();
    } else {
        long diffTime = nowTime - bestRoundData.getRoundEndTime();
        int diffRoundCount = (int) (diffTime / (bestRoundData.getConsensusMemberCount() * ProtocolConstant.BLOCK_TIME_INTERVAL_SECOND * 1000L));
        index = bestRoundData.getRoundIndex() + diffRoundCount + 1;
        startTime = bestRoundData.getRoundEndTime() + diffRoundCount * bestRoundData.getConsensusMemberCount() * ProtocolConstant.BLOCK_TIME_INTERVAL_SECOND * 1000L;
    }
    return calculationRound(startBlockHeader, index, startTime);
}
Also used : BlockHeader(io.nuls.kernel.model.BlockHeader)

Example 15 with BlockHeader

use of io.nuls.kernel.model.BlockHeader in project nuls by nuls-io.

the class StopAgentTxProcessor method onCommit.

@Override
public Result onCommit(StopAgentTransaction tx, Object secondaryData) {
    BlockHeader header = (BlockHeader) secondaryData;
    if (tx.getTime() < (header.getTime() - 300000L)) {
        return Result.getFailed(PocConsensusErrorCode.LOCK_TIME_NOT_REACHED);
    }
    AgentPo agentPo = agentStorageService.get(tx.getTxData().getCreateTxHash());
    if (null == agentPo || agentPo.getDelHeight() > 0) {
        throw new NulsRuntimeException(PocConsensusErrorCode.AGENT_NOT_EXIST);
    }
    List<DepositPo> depositPoList = depositStorageService.getList();
    for (DepositPo depositPo : depositPoList) {
        if (depositPo.getDelHeight() > -1L) {
            continue;
        }
        if (!depositPo.getAgentHash().equals(agentPo.getHash())) {
            continue;
        }
        depositPo.setDelHeight(tx.getBlockHeight());
        depositStorageService.save(depositPo);
    }
    agentPo.setDelHeight(tx.getBlockHeight());
    tx.getTxData().setAddress(agentPo.getAgentAddress());
    boolean b = agentStorageService.save(agentPo);
    if (!b) {
        return Result.getFailed(PocConsensusErrorCode.UPDATE_AGENT_FAILED);
    }
    return Result.getSuccess();
}
Also used : DepositPo(io.nuls.consensus.poc.storage.po.DepositPo) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) BlockHeader(io.nuls.kernel.model.BlockHeader) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

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