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;
}
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;
}
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);
}
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);
}
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();
}
Aggregations