use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class RepositoryImplTest method getAccountsKeysOnSnapshot.
@Test
public void getAccountsKeysOnSnapshot() {
RskAddress accAddress1 = randomAccountAddress();
RskAddress accAddress2 = randomAccountAddress();
TrieStore store = new TrieStoreImpl(new HashMapDB());
RepositoryImpl repository = new RepositoryImpl(config, store);
repository.createAccount(accAddress1);
repository.flush();
byte[] root = repository.getRoot();
repository.createAccount(accAddress2);
repository.syncToRoot(root);
Set<RskAddress> keys = repository.getAccountsKeys();
Assert.assertNotNull(keys);
Assert.assertFalse(keys.isEmpty());
Assert.assertEquals(1, keys.size());
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class RepositoryBuilder method build.
public static Repository build(Map<String, AccountTck> accounts) {
HashMap<RskAddress, AccountState> stateBatch = new HashMap<>();
HashMap<RskAddress, ContractDetails> detailsBatch = new HashMap<>();
for (String address : accounts.keySet()) {
RskAddress addr = new RskAddress(address);
AccountTck accountTCK = accounts.get(address);
AccountBuilder.StateWrap stateWrap = AccountBuilder.build(accountTCK);
AccountState state = stateWrap.getAccountState();
ContractDetails details = stateWrap.getContractDetails();
stateBatch.put(addr, state);
ContractDetailsCacheImpl detailsCache = new ContractDetailsCacheImpl(details);
detailsCache.setDirty(true);
detailsBatch.put(addr, detailsCache);
}
RepositoryImpl repositoryDummy = new RepositoryImpl(new RskSystemProperties(), new TrieStoreImpl(new HashMapDB()));
Repository track = repositoryDummy.startTracking();
track.updateBatch(stateBatch, detailsBatch);
track.commit();
return repositoryDummy;
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class RskTestFactory method getRepository.
public Repository getRepository() {
if (repository == null) {
HashMapDB stateStore = new HashMapDB();
repository = new RepositoryImpl(config, new TrieStoreImpl(stateStore));
}
return repository;
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class BlockChainBuilder method build.
public BlockChainImpl build(boolean withoutCleaner) {
if (repository == null)
repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
if (blockStore == null) {
blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
}
if (receiptStore == null) {
KeyValueDataSource ds = new HashMapDB();
ds.init();
receiptStore = new ReceiptStoreImpl(ds);
}
if (txinfos != null && !txinfos.isEmpty())
for (TransactionInfo txinfo : txinfos) receiptStore.add(txinfo.getBlockHash(), txinfo.getIndex(), txinfo.getReceipt());
EthereumListener listener = new BlockExecutorTest.SimpleEthereumListener();
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).blockStore(blockStore);
BlockValidator blockValidator = validatorBuilder.build();
if (this.adminInfo == null)
this.adminInfo = new AdminInfo();
BlockChainImpl blockChain = new BlockChainImpl(config, this.repository, this.blockStore, receiptStore, null, listener, this.adminInfo, blockValidator);
if (this.testing) {
blockChain.setBlockValidator(new DummyBlockValidator());
blockChain.setNoValidation(true);
}
TransactionPoolImpl transactionPool;
if (withoutCleaner) {
transactionPool = new TransactionPoolImplNoCleaner(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
} else {
transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
}
blockChain.setTransactionPool(transactionPool);
if (this.genesis != null) {
for (RskAddress addr : this.genesis.getPremine().keySet()) {
this.repository.createAccount(addr);
this.repository.addBalance(addr, this.genesis.getPremine().get(addr).getAccountState().getBalance());
}
Repository track = this.repository.startTracking();
new RepositoryBlockStore(config, track, PrecompiledContracts.BRIDGE_ADDR);
track.commit();
this.genesis.setStateRoot(this.repository.getRoot());
this.genesis.flushRLP();
blockChain.setBestBlock(this.genesis);
blockChain.setTotalDifficulty(this.genesis.getCumulativeDifficulty());
}
if (this.blocks != null) {
BlockExecutor blockExecutor = new BlockExecutor(config, repository, receiptStore, blockStore, listener);
for (Block b : this.blocks) {
blockExecutor.executeAndFillAll(b, blockChain.getBestBlock());
blockChain.tryToConnect(b);
}
}
return blockChain;
}
use of co.rsk.trie.TrieStoreImpl in project rskj by rsksmart.
the class DoPrune method doPrune.
public void doPrune(String[] args) throws Exception {
logger.info("Pruning Database");
int blocksToProcess = DEFAULT_BLOCKS_TO_PROCESS;
RskAddress contractAddress = DEFAULT_CONTRACT_ADDRESS;
CLIInterface.call(rskSystemProperties, args);
logger.info("Running {}, core version: {}-{}", rskSystemProperties.genesisInfo(), rskSystemProperties.projectVersion(), rskSystemProperties.projectVersionModifier());
BuildInfo.printInfo();
long height = this.blockchain.getBestBlock().getNumber();
String dataSourceName = getDataSourceName(contractAddress);
logger.info("Datasource Name {}", dataSourceName);
logger.info("Blockchain height {}", height);
TrieImpl source = new TrieImpl(new TrieStoreImpl(levelDbByName(this.rskSystemProperties, dataSourceName)), true);
KeyValueDataSource targetDataSource = levelDbByName(this.rskSystemProperties, dataSourceName + "B");
TrieStore targetStore = new TrieStoreImpl(targetDataSource);
this.processBlocks(height - blocksToProcess, source, contractAddress, targetStore);
targetDataSource.close();
}
Aggregations