Search in sources :

Example 1 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class IndexedBlockStoreTest method test6.

// leveldb + mapdb, multi branch, total difficulty test
@Test
public void test6() throws IOException {
    BigInteger bi = new BigInteger(32, new Random());
    String testDir = "test_db_" + bi;
    config.setDataBaseDir(testDir);
    DB indexDB = createMapDB(testDir);
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = createIndexMap(indexDB);
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    try {
        IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
        Block genesis = Genesis.getInstance(config);
        List<Block> bestLine = getRandomChain(genesis.getHash().getBytes(), 1, 100);
        indexedBlockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
        BlockDifficulty td = genesis.getCumulativeDifficulty();
        for (int i = 0; i < bestLine.size(); ++i) {
            Block newBlock = bestLine.get(i);
            td = td.add(newBlock.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(newBlock, td, true);
        }
        byte[] forkParentHash = bestLine.get(60).getHash().getBytes();
        long forkParentNumber = bestLine.get(60).getNumber();
        List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 50);
        for (int i = 0; i < forkLine.size(); ++i) {
            Block newBlock = forkLine.get(i);
            Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash().getBytes());
            td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash().getBytes());
            td = td.add(newBlock.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(newBlock, td, false);
        }
        // calc all TDs
        Map<Keccak256, BlockDifficulty> tDiffs = new HashMap<>();
        td = Genesis.getInstance(config).getCumulativeDifficulty();
        for (Block block : bestLine) {
            td = td.add(block.getCumulativeDifficulty());
            tDiffs.put(block.getHash(), td);
        }
        Map<Keccak256, BlockDifficulty> tForkDiffs = new HashMap<>();
        Block block = forkLine.get(0);
        td = tDiffs.get(block.getParentHash());
        for (Block currBlock : forkLine) {
            td = td.add(currBlock.getCumulativeDifficulty());
            tForkDiffs.put(currBlock.getHash(), td);
        }
        // Assert tds on bestLine
        for (Keccak256 hash : tDiffs.keySet()) {
            BlockDifficulty currTD = tDiffs.get(hash);
            BlockDifficulty checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getBytes());
            assertEquals(checkTd, currTD);
        }
        // Assert tds on forkLine
        for (Keccak256 hash : tForkDiffs.keySet()) {
            BlockDifficulty currTD = tForkDiffs.get(hash);
            BlockDifficulty checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getBytes());
            assertEquals(checkTd, currTD);
        }
        indexedBlockStore.flush();
        // Assert tds on bestLine
        for (Keccak256 hash : tDiffs.keySet()) {
            BlockDifficulty currTD = tDiffs.get(hash);
            BlockDifficulty checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getBytes());
            assertEquals(checkTd, currTD);
        }
        // check total difficulty
        Block bestBlock = bestLine.get(bestLine.size() - 1);
        BlockDifficulty totalDifficulty = indexedBlockStore.getTotalDifficultyForHash(bestBlock.getHash().getBytes());
        BlockDifficulty totalDifficulty_ = tDiffs.get(bestBlock.getHash());
        assertEquals(totalDifficulty_, totalDifficulty);
        // Assert tds on forkLine
        for (Keccak256 hash : tForkDiffs.keySet()) {
            BlockDifficulty currTD = tForkDiffs.get(hash);
            BlockDifficulty checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getBytes());
            assertEquals(checkTd, currTD);
        }
    } finally {
        blocksDB.close();
        indexDB.close();
        FileUtil.recursiveDelete(testDir);
    }
}
Also used : Keccak256(co.rsk.crypto.Keccak256) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) BlockDifficulty(co.rsk.core.BlockDifficulty) BigInteger(java.math.BigInteger) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) HashMapDB(org.ethereum.datasource.HashMapDB) DB(org.mapdb.DB) Test(org.junit.Test)

Example 2 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class TestRunner method runTestCase.

public List<String> runTestCase(BlockTestCase testCase) {
    /* 1 */
    // Create genesis + init pre state
    Block genesis = BlockBuilder.build(testCase.getGenesisBlockHeader(), null, null);
    Repository repository = RepositoryBuilder.build(testCase.getPre());
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    EthereumListener listener = new CompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, null, null, new DummyBlockValidator());
    // BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository, wallet, adminInfo, listener,
    // new CommonConfig().parentHeaderValidator(), receiptStore);
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    blockchain.setTransactionPool(transactionPool);
    /* 2 */
    // Create block traffic list
    List<Block> blockTraffic = new ArrayList<>();
    for (BlockTck blockTck : testCase.getBlocks()) {
        Block block = BlockBuilder.build(blockTck.getBlockHeader(), blockTck.getTransactions(), blockTck.getUncleHeaders());
        setNewStateRoot = !((blockTck.getTransactions() == null) && (blockTck.getUncleHeaders() == null) && (blockTck.getBlockHeader() == null));
        Block tBlock = null;
        try {
            byte[] rlp = parseData(blockTck.getRlp());
            tBlock = new Block(rlp);
            ArrayList<String> outputSummary = BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader());
            if (!outputSummary.isEmpty()) {
                for (String output : outputSummary) logger.error("at block {}: {}", Integer.toString(blockTraffic.size()), output);
            }
            blockTraffic.add(tBlock);
        } catch (Exception e) {
            System.out.println("*** Exception");
        }
    }
    // Inject blocks to the blockchain execution
    for (Block block : blockTraffic) {
        ImportResult importResult = blockchain.tryToConnect(block);
        logger.debug("{} ~ {} difficulty: {} ::: {}", block.getShortHash(), shortHash(block.getParentHash().getBytes()), block.getCumulativeDifficulty(), importResult.toString());
    }
    // Check state root matches last valid block
    List<String> results = new ArrayList<>();
    String currRoot = Hex.toHexString(repository.getRoot());
    byte[] bestHash = Hex.decode(testCase.getLastblockhash());
    String finalRoot = Hex.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot());
    /*
        if (!blockchain.byTest) // If this comes from ETH, it won't match
        if (!finalRoot.equals(currRoot)){
            String formattedString = String.format("Root hash doesn't match best: expected: %s current: %s",
                    finalRoot, currRoot);
            results.add(formattedString);
        }
        */
    Repository postRepository = RepositoryBuilder.build(testCase.getPostState());
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false);
    results.addAll(repoResults);
    return results;
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) EthereumListener(org.ethereum.listener.EthereumListener) ImportResult(org.ethereum.core.ImportResult) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) IOException(java.io.IOException) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) Repository(org.ethereum.core.Repository) BlockTck(org.ethereum.jsontestsuite.model.BlockTck) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Block(org.ethereum.core.Block) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource)

Example 3 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis) {
    RskSystemProperties config = new RskSystemProperties();
    config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {

        @Override
        public BlockDifficulty getMinimumDifficulty() {
            return new BlockDifficulty(BigInteger.ONE);
        }
    }));
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
    EthereumListenerAdapter listener = new EthereumListenerAdapter();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setTransactionPool(transactionPool);
    Repository track = repository.startTracking();
    for (RskAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) AdminInfo(org.ethereum.manager.AdminInfo) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties) ReceiptStore(org.ethereum.db.ReceiptStore) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig)

Example 4 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class IndexedBlockStoreTest method test5.

// leveldb + mapdb, save part to disk part to cache, and check it exist
@Test
@Ignore
public void test5() throws IOException {
    BigInteger bi = new BigInteger(32, new Random());
    String testDir = "test_db_" + bi;
    config.setDataBaseDir(testDir);
    DB indexDB = createMapDB(testDir);
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = createIndexMap(indexDB);
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    try {
        IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
        BlockDifficulty cummDiff = BlockDifficulty.ZERO;
        int preloadSize = blocks.size() / 2;
        for (int i = 0; i < preloadSize; ++i) {
            Block block = blocks.get(i);
            cummDiff = cummDiff.add(block.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(block, cummDiff, true);
        }
        indexedBlockStore.flush();
        for (int i = preloadSize; i < blocks.size(); ++i) {
            Block block = blocks.get(i);
            cummDiff = cummDiff.add(block.getCumulativeDifficulty());
            indexedBlockStore.saveBlock(block, cummDiff, true);
        }
        // testing:   getTotalDifficultyForHash(byte[])
        // testing:   getMaxNumber()
        long bestIndex = blocks.get(blocks.size() - 1).getNumber();
        assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
        assertEquals(cumDifficulty, indexedBlockStore.getTotalDifficultyForHash(blocks.get(blocks.size() - 1).getHash().getBytes()));
        // testing:  getBlockByHash(byte[])
        Block block = blocks.get(50);
        Block block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(150);
        block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(0);
        block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(8003);
        block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
        assertEquals(block.getNumber(), block_.getNumber());
        block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
        assertEquals(null, block_);
        // testing:  getChainBlockByNumber(long)
        block = blocks.get(50);
        block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(150);
        block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(0);
        block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
        assertEquals(block.getNumber(), block_.getNumber());
        block = blocks.get(8003);
        block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
        assertEquals(block.getNumber(), block_.getNumber());
        block_ = indexedBlockStore.getChainBlockByNumber(10000);
        assertEquals(null, block_);
        // testing: getBlocksInformationByNumber(long)
        block = blocks.get(50);
        BlockInformation blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
        Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
        Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
        block = blocks.get(150);
        blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
        Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
        Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
        block = blocks.get(0);
        blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
        Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
        Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
        block = blocks.get(8003);
        blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
        Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
        Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
        int blocksNum = indexedBlockStore.getBlocksInformationByNumber(10000).size();
        assertEquals(0, blocksNum);
        // testing: getListHashesEndWith(byte[], long)
        block = blocks.get(8003);
        List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash().getBytes(), 100);
        for (int i = 0; i < 100; ++i) {
            block = blocks.get(8003 - i);
            String hash = Hex.toHexString(hashList.get(i));
            String hash_ = Hex.toHexString(block.getHash().getBytes());
            assertEquals(hash_, hash);
        }
        // testing: getListHashesStartWith(long, long)
        block = blocks.get(7003);
        hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
        for (int i = 0; i < 100; ++i) {
            block = blocks.get(7003 + i);
            String hash = Hex.toHexString(hashList.get(i));
            String hash_ = Hex.toHexString(block.getHash().getBytes());
            assertEquals(hash_, hash);
        }
        indexedBlockStore.flush();
        blocksDB.close();
        indexDB.close();
        // testing after: REOPEN
        indexDB = createMapDB(testDir);
        indexMap = createIndexMap(indexDB);
        blocksDB = new LevelDbDataSource(config, "blocks");
        blocksDB.init();
        indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
        // testing: getListHashesStartWith(long, long)
        block = blocks.get(7003);
        hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
        for (int i = 0; i < 100; ++i) {
            block = blocks.get(7003 + i);
            String hash = Hex.toHexString(hashList.get(i));
            String hash_ = Hex.toHexString(block.getHash().getBytes());
            assertEquals(hash_, hash);
        }
    } finally {
        blocksDB.close();
        indexDB.close();
        FileUtil.recursiveDelete(testDir);
    }
}
Also used : LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) BlockDifficulty(co.rsk.core.BlockDifficulty) BigInteger(java.math.BigInteger) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) HashMapDB(org.ethereum.datasource.HashMapDB) DB(org.mapdb.DB) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with KeyValueDataSource

use of org.ethereum.datasource.KeyValueDataSource in project rskj by rsksmart.

the class IndexedBlockStoreTest method test4.

// leveldb + mapdb, save some load, flush to disk, and check it exist
@Test
@Ignore
public void test4() throws IOException {
    BigInteger bi = new BigInteger(32, new Random());
    String testDir = "test_db_" + bi;
    config.setDataBaseDir(testDir);
    DB indexDB = createMapDB(testDir);
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = createIndexMap(indexDB);
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
    BlockDifficulty cummDiff = BlockDifficulty.ZERO;
    for (Block block : blocks) {
        cummDiff = cummDiff.add(block.getCumulativeDifficulty());
        indexedBlockStore.saveBlock(block, cummDiff, true);
    }
    // testing:   getTotalDifficultyForHash(byte[])
    // testing:   getMaxNumber()
    long bestIndex = blocks.get(blocks.size() - 1).getNumber();
    assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
    assertEquals(cumDifficulty, indexedBlockStore.getTotalDifficultyForHash(blocks.get(blocks.size() - 1).getHash().getBytes()));
    // testing:  getBlockByHash(byte[])
    Block block = blocks.get(50);
    Block block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(150);
    block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(0);
    block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(8003);
    block_ = indexedBlockStore.getBlockByHash(block.getHash().getBytes());
    assertEquals(block.getNumber(), block_.getNumber());
    block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
    assertEquals(null, block_);
    // testing:  getChainBlockByNumber(long)
    block = blocks.get(50);
    block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(150);
    block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(0);
    block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
    assertEquals(block.getNumber(), block_.getNumber());
    block = blocks.get(8003);
    block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
    assertEquals(block.getNumber(), block_.getNumber());
    block_ = indexedBlockStore.getChainBlockByNumber(10000);
    assertEquals(null, block_);
    // testing: getBlocksInformationByNumber(long)
    block = blocks.get(50);
    BlockInformation blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
    Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
    Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
    block = blocks.get(150);
    blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
    Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
    Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
    block = blocks.get(0);
    blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
    Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
    Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
    block = blocks.get(8003);
    blockInformation = indexedBlockStore.getBlocksInformationByNumber(block.getNumber()).get(0);
    Assert.assertArrayEquals(block.getHash().getBytes(), blockInformation.getHash());
    Assert.assertTrue(blockInformation.getTotalDifficulty().compareTo(ZERO) > 0);
    int blocksNum = indexedBlockStore.getBlocksInformationByNumber(10000).size();
    assertEquals(0, blocksNum);
    // testing: getListHashesEndWith(byte[], long)
    block = blocks.get(8003);
    List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash().getBytes(), 100);
    for (int i = 0; i < 100; ++i) {
        block = blocks.get(8003 - i);
        String hash = Hex.toHexString(hashList.get(i));
        String hash_ = Hex.toHexString(block.getHash().getBytes());
        assertEquals(hash_, hash);
    }
    // testing: getListHashesStartWith(long, long)
    block = blocks.get(7003);
    hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
    for (int i = 0; i < 100; ++i) {
        block = blocks.get(7003 + i);
        String hash = Hex.toHexString(hashList.get(i));
        String hash_ = Hex.toHexString(block.getHash().getBytes());
        assertEquals(hash_, hash);
    }
    blocksDB.close();
    indexDB.close();
    // testing after: REOPEN
    indexDB = createMapDB(testDir);
    indexMap = createIndexMap(indexDB);
    blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
    // testing: getListHashesStartWith(long, long)
    block = blocks.get(7003);
    hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
    for (int i = 0; i < 100; ++i) {
        block = blocks.get(7003 + i);
        String hash = Hex.toHexString(hashList.get(i));
        String hash_ = Hex.toHexString(block.getHash().getBytes());
        assertEquals(hash_, hash);
    }
    blocksDB.close();
    indexDB.close();
    FileUtil.recursiveDelete(testDir);
}
Also used : LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) BlockDifficulty(co.rsk.core.BlockDifficulty) BigInteger(java.math.BigInteger) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Block(org.ethereum.core.Block) HashMapDB(org.ethereum.datasource.HashMapDB) DB(org.mapdb.DB) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)26 HashMapDB (org.ethereum.datasource.HashMapDB)13 Test (org.junit.Test)13 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)10 BlockDifficulty (co.rsk.core.BlockDifficulty)6 Block (org.ethereum.core.Block)6 DB (org.mapdb.DB)6 BigInteger (java.math.BigInteger)5 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 Bean (org.springframework.context.annotation.Bean)4 RskAddress (co.rsk.core.RskAddress)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 EthereumListener (org.ethereum.listener.EthereumListener)3 AdminInfo (org.ethereum.manager.AdminInfo)3 RskSystemProperties (co.rsk.config.RskSystemProperties)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2