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);
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations