use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class ConsensusMeetingRunner method calcRound.
private PocMeetingRound calcRound() {
PocMeetingRound round = new PocMeetingRound(this.consensusManager.getCurrentRound());
Block bestBlock = context.getBestBlock();
BlockRoundData lastRoundData;
try {
lastRoundData = new BlockRoundData(bestBlock.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
throw new NulsRuntimeException(e);
}
if (round.getPreviousRound() == null || round.getPreviousRound().getIndex() <= lastRoundData.getRoundIndex()) {
while (true) {
if (lastRoundData.getPackingIndexOfRound() == lastRoundData.getConsensusMemberCount() || lastRoundData.getRoundEndTime() <= TimeService.currentTimeMillis()) {
break;
}
try {
bestBlock = context.getBestBlock();
lastRoundData = new BlockRoundData(bestBlock.getHeader().getExtend());
} catch (NulsException e) {
Log.error(e);
}
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
Log.error(e);
}
}
PocMeetingRound preRound = new PocMeetingRound(null);
preRound.setIndex(lastRoundData.getRoundIndex());
preRound.setStartTime(lastRoundData.getRoundStartTime());
preRound.setMemberCount(lastRoundData.getConsensusMemberCount());
round.setPreviousRound(preRound);
}
round.setStartTime(round.getPreviousRound().getEndTime());
round.setIndex(lastRoundData.getRoundIndex() + 1);
return round;
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockManager method rollbackAppraval.
private void rollbackAppraval(Block block) {
if (null == block) {
Log.warn("the block is null!");
return;
}
this.rollbackTxList(block.getTxs(), 0, block.getTxs().size());
List<String> hashList = this.bifurcateProcessor.getHashList(block.getHeader().getHeight() - 1);
if (hashList.size() > 1) {
Block preBlock = confrimingBlockCacheManager.getBlock(block.getHeader().getPreHash().getDigestHex());
this.rollbackAppraval(preBlock);
}
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class BlockHeaderHandler method onEvent.
@Override
public void onEvent(BlockHeaderEvent event, String fromId) {
BlockHeader header = event.getEventBody();
if (null == header) {
Log.warn("recieved a null blockHeader!");
return;
}
Block block = blockManager.getBlock(header.getHash().getDigestHex());
if (null != block) {
return;
}
GetSmallBlockRequest request = new GetSmallBlockRequest();
GetSmallBlockParam param = new GetSmallBlockParam();
param.setBlockHash(header.getHash());
request.setEventBody(param);
eventBroadcaster.sendToNode(request, fromId);
temporaryCacheManager.cacheBlockHeader(header);
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class GetBlockHandler method onEvent.
@Override
public void onEvent(GetBlockRequest event, String fromId) throws NulsException {
List<Block> blockList = blockService.getBlockList(event.getStart(), event.getEnd());
for (Block block : blockList) {
if (null == block) {
continue;
}
BlockEvent blockEvent = new BlockEvent();
blockEvent.setEventBody(block);
eventBroadcaster.sendToNode(blockEvent, fromId);
}
}
use of io.nuls.core.chain.entity.Block in project nuls by nuls-io.
the class GetBlockHeaderHandler method onEvent.
@Override
public void onEvent(GetBlockHeaderEvent event, String fromId) {
BlockHeader header;
if (null == event.getEventBody() || event.getEventBody().getHeight() == 0) {
header = blockService.getLocalBestBlock().getHeader();
} else {
Block block = blockService.getBlock(event.getEventBody().getHeight());
if (null == block) {
header = new BlockHeader();
header.setHeight(event.getEventBody().getHeight());
} else {
header = block.getHeader();
}
}
if (header == null) {
Log.error("header cannot be null");
return;
}
this.eventBroadcaster.sendToNode(new BlockHeaderEvent(header), fromId);
}
Aggregations