Search in sources :

Example 6 with LevelDbDataSource

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

the class DefaultConfig method receiptStore.

@Bean
public ReceiptStore receiptStore(RskSystemProperties config) {
    KeyValueDataSource ds = new LevelDbDataSource(config, "receipts");
    ds.init();
    return new ReceiptStoreImpl(ds);
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) Bean(org.springframework.context.annotation.Bean)

Example 7 with LevelDbDataSource

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

the class DefaultConfig method blockStore.

@Bean
public BlockStore blockStore(RskSystemProperties config) {
    String database = config.databaseDir();
    File blockIndexDirectory = new File(database + "/blocks/");
    File dbFile = new File(blockIndexDirectory, "index");
    if (!blockIndexDirectory.exists()) {
        boolean mkdirsSuccess = blockIndexDirectory.mkdirs();
        if (!mkdirsSuccess) {
            logger.error("Unable to create blocks directory: {}", blockIndexDirectory);
        }
    }
    DB indexDB = DBMaker.fileDB(dbFile).closeOnJvmShutdown().make();
    Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index").keySerializer(Serializer.LONG).valueSerializer(BLOCK_INFO_SERIALIZER).counterEnable().makeOrGet();
    KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
    blocksDB.init();
    IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
    return indexedBlockStore;
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) List(java.util.List) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) File(java.io.File) DB(org.mapdb.DB) Bean(org.springframework.context.annotation.Bean)

Example 8 with LevelDbDataSource

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

the class WalletFactory method createPersistentWallet.

public static Wallet createPersistentWallet(String storeName) {
    KeyValueDataSource ds = new LevelDbDataSource(new RskSystemProperties(), storeName);
    ds.init();
    return new Wallet(ds);
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 9 with LevelDbDataSource

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

the class IndexedBlockStoreTest method test7.

// leveldb + mapdb, multi branch, total re-branch test
@Test
public void test7() 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);
        }
        Block bestBlock = bestLine.get(bestLine.size() - 1);
        Block forkBlock = forkLine.get(forkLine.size() - 1);
        indexedBlockStore.reBranch(forkBlock);
    } 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) Test(org.junit.Test)

Example 10 with LevelDbDataSource

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

the class RskFactory method getWallet.

@Bean
public Wallet getWallet(RskSystemProperties config) {
    if (!config.isWalletEnabled()) {
        logger.info("Local wallet disabled");
        return null;
    }
    logger.info("Local wallet enabled");
    KeyValueDataSource ds = new LevelDbDataSource(config, "wallet");
    ds.init();
    return new Wallet(ds);
}
Also used : KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) LevelDbDataSource(org.ethereum.datasource.LevelDbDataSource) Bean(org.springframework.context.annotation.Bean)

Aggregations

KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)10 LevelDbDataSource (org.ethereum.datasource.LevelDbDataSource)10 DB (org.mapdb.DB)6 BlockDifficulty (co.rsk.core.BlockDifficulty)5 BigInteger (java.math.BigInteger)5 Block (org.ethereum.core.Block)5 HashMapDB (org.ethereum.datasource.HashMapDB)5 Test (org.junit.Test)5 Bean (org.springframework.context.annotation.Bean)3 Ignore (org.junit.Ignore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 Keccak256 (co.rsk.crypto.Keccak256)1 File (java.io.File)1 List (java.util.List)1