use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class RoundManager method checkIsNeedReset.
public void checkIsNeedReset() {
if (roundList == null || roundList.size() == 0) {
initRound();
} else {
Lockers.ROUND_LOCK.lock();
try {
MeetingRound lastRound = roundList.get(roundList.size() - 1);
Block bestBlcok = chain.getBestBlock();
BlockExtendsData blockRoundData = new BlockExtendsData(bestBlcok.getHeader().getExtend());
if (blockRoundData.getRoundIndex() < lastRound.getIndex()) {
roundList.clear();
initRound();
}
} finally {
Lockers.ROUND_LOCK.unlock();
}
}
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ConsensusDownloadServiceImpl method downloadBlock.
@Override
public Result<Block> downloadBlock(NulsDigestData hash, Node node) {
Result<Block> result = new Result<>();
Block block = new Block();
block.setTxs(new ArrayList<>());
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHash(hash);
block.setHeader(blockHeader);
result.setData(block);
return result;
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ChainManagerTest method testGetBestBlockHeight.
@Test
public void testGetBestBlockHeight() {
assertNotNull(chainManager);
Block block = createBlock();
ChainContainer masterChain = new ChainContainer(new Chain());
chainManager.setMasterChain(masterChain);
masterChain.getChain().addBlock(block);
assertEquals(0L, chainManager.getBestBlockHeight());
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ChainManagerTest method testNewOrphanChain.
@Test
public void testNewOrphanChain() {
assertNotNull(chainManager);
Block block = createBlock();
chainManager.newOrphanChain(block);
assertEquals(1, chainManager.getOrphanChains().size());
}
use of io.nuls.kernel.model.Block in project nuls by nuls-io.
the class ChainManagerTest method testCheckIsAfterOrphanChainAndAdd.
@Test
public void testCheckIsAfterOrphanChainAndAdd() {
testGetBestBlockHeight();
Block block = createBlock();
Block block1 = createBlock();
block1.getHeader().setHeight(1L);
block1.getHeader().setPreHash(block.getHeader().getHash());
ChainContainer orphanChain = new ChainContainer(new Chain());
orphanChain.getChain().addBlock(block);
chainManager.getOrphanChains().add(orphanChain);
assertEquals(1, chainManager.getOrphanChains().size());
boolean success = chainManager.checkIsAfterOrphanChainAndAdd(block1);
assertTrue(success);
}
Aggregations