Search in sources :

Example 26 with Block

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

the class ConsensusBlockServiceImpl method getBlock.

@Override
public Result<Block> getBlock(NulsDigestData hash) {
    Result result = new Result(true, null);
    Block block = new Block();
    BlockHeader blockHeader = new BlockHeader();
    blockHeader.setHash(hash);
    block.setHeader(blockHeader);
    block.setTxs(new ArrayList<>());
    result.setData(block);
    return result;
}
Also used : Block(io.nuls.kernel.model.Block) SmallBlock(io.nuls.protocol.model.SmallBlock) BlockHeader(io.nuls.kernel.model.BlockHeader) Result(io.nuls.kernel.model.Result)

Example 27 with Block

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

the class ChainManagerTest method testCheckIsBeforeOrphanChainAndAdd.

@Test
public void testCheckIsBeforeOrphanChainAndAdd() {
    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(block1);
    chainManager.getOrphanChains().add(orphanChain);
    assertEquals(1, chainManager.getOrphanChains().size());
    boolean success = chainManager.checkIsBeforeOrphanChainAndAdd(block);
    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)

Example 28 with Block

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

the class BlockQueueProviderTest method testPut.

@Test
public void testPut() {
    assertNotNull(blockQueueProvider);
    assertEquals(0, blockQueueProvider.size());
    Block block = new Block();
    boolean result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
    assertTrue(result);
    assertEquals(1, blockQueueProvider.size());
}
Also used : BlockContainer(io.nuls.consensus.poc.container.BlockContainer) Block(io.nuls.kernel.model.Block) Test(org.junit.Test) BaseTest(io.nuls.consensus.poc.BaseTest)

Example 29 with Block

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

the class BlockQueueProviderTest method testGet.

@Test
public void testGet() {
    assertNotNull(blockQueueProvider);
    assertEquals(0, blockQueueProvider.size());
    if (downloadService.isDownloadSuccess().isSuccess()) {
        downloadService.setDownloadSuccess(false);
    }
    Block block = new Block();
    boolean result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
    assertTrue(result);
    assertEquals(1, blockQueueProvider.size());
    BlockContainer blockContainer = blockQueueProvider.get();
    assertNull(blockContainer);
    downloadService.setDownloadSuccess(true);
    blockContainer = blockQueueProvider.get();
    assertNotNull(blockContainer);
    assertEquals(blockContainer.getBlock(), block);
    assertEquals(blockContainer.getStatus(), BlockContainerStatus.DOWNLOADING);
    assertEquals(0, blockQueueProvider.size());
    block = new Block();
    result = blockQueueProvider.put(new BlockContainer(block, BlockContainerStatus.RECEIVED));
    assertTrue(result);
    blockContainer = blockQueueProvider.get();
    assertNotNull(blockContainer);
    assertEquals(blockContainer.getBlock(), block);
    assertEquals(blockContainer.getStatus(), BlockContainerStatus.RECEIVED);
}
Also used : BlockContainer(io.nuls.consensus.poc.container.BlockContainer) Block(io.nuls.kernel.model.Block) Test(org.junit.Test) BaseTest(io.nuls.consensus.poc.BaseTest)

Example 30 with Block

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

the class BaseProtocolsModuleBootstrap method start.

@Override
public void start() {
    this.waitForDependencyRunning(MessageBusConstant.MODULE_ID_MESSAGE_BUS);
    this.waitForDependencyInited(ConsensusConstant.MODULE_ID_CONSENSUS, NetworkConstant.NETWORK_MODULE_ID);
    BlockService blockService = NulsContext.getServiceBean(BlockService.class);
    Block block0 = blockService.getGengsisBlock().getData();
    Block genesisBlock = NulsContext.getInstance().getGenesisBlock();
    if (null == block0) {
        try {
            blockService.saveBlock(genesisBlock);
        } catch (NulsException e) {
            Log.error(e);
            throw new NulsRuntimeException(e);
        }
    }
    Block block = blockService.getBestBlock().getData();
    while (null != block && block.verify().isFailed()) {
        try {
            blockService.rollbackBlock(block);
        } catch (NulsException e) {
            Log.error(e);
        }
        block = blockService.getBlock(block.getHeader().getPreHash()).getData();
    }
    if (null != block) {
        NulsContext.getInstance().setBestBlock(block);
        this.initHandlers();
        ((DownloadServiceImpl) NulsContext.getServiceBean(DownloadService.class)).start();
    } else {
        start();
    }
}
Also used : DownloadServiceImpl(io.nuls.protocol.base.service.DownloadServiceImpl) NulsException(io.nuls.kernel.exception.NulsException) BlockService(io.nuls.protocol.service.BlockService) Block(io.nuls.kernel.model.Block) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) DownloadService(io.nuls.protocol.service.DownloadService)

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