Search in sources :

Example 11 with Block

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

Example 12 with Block

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

Example 13 with Block

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

Example 14 with Block

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());
}
Also used : Block(io.nuls.kernel.model.Block) Test(org.junit.Test) BaseTest(io.nuls.consensus.poc.BaseTest)

Example 15 with Block

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

Aggregations

Block (io.nuls.kernel.model.Block)34 NulsDigestData (io.nuls.kernel.model.NulsDigestData)9 Test (org.junit.Test)9 BaseTest (io.nuls.consensus.poc.BaseTest)8 BlockHeader (io.nuls.kernel.model.BlockHeader)8 BlockContainer (io.nuls.consensus.poc.container.BlockContainer)4 ChainContainer (io.nuls.consensus.poc.container.ChainContainer)4 Chain (io.nuls.consensus.poc.model.Chain)4 Result (io.nuls.kernel.model.Result)4 NulsException (io.nuls.kernel.exception.NulsException)3 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)3 Node (io.nuls.network.model.Node)3 DownloadService (io.nuls.protocol.service.DownloadService)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MicroKernelBootstrap (io.nuls.kernel.MicroKernelBootstrap)2 CompleteParam (io.nuls.protocol.model.CompleteParam)2 SmallBlock (io.nuls.protocol.model.SmallBlock)2 BlockService (io.nuls.protocol.service.BlockService)2 HashSet (java.util.HashSet)2