Search in sources :

Example 41 with TrieStore

use of co.rsk.trie.TrieStore in project rskj by rsksmart.

the class RepositoryImplTest method syncToRootAfterCreatingAnAccount.

@Test
public void syncToRootAfterCreatingAnAccount() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    RepositoryImpl repository = new RepositoryImpl(config, store);
    repository.flush();
    RskAddress accAddress = randomAccountAddress();
    byte[] initialRoot = repository.getRoot();
    repository.createAccount(accAddress);
    repository.flush();
    byte[] newRoot = repository.getRoot();
    Assert.assertTrue(repository.isExist(accAddress));
    repository.syncToRoot(initialRoot);
    Assert.assertFalse(repository.isExist(accAddress));
    repository.syncToRoot(newRoot);
    Assert.assertTrue(repository.isExist(accAddress));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RskAddress(co.rsk.core.RskAddress) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 42 with TrieStore

use of co.rsk.trie.TrieStore 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());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RskAddress(co.rsk.core.RskAddress) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) TrieImplHashTest(co.rsk.trie.TrieImplHashTest) Test(org.junit.Test)

Example 43 with TrieStore

use of co.rsk.trie.TrieStore 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();
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) TrieImpl(co.rsk.trie.TrieImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) TrieStore(co.rsk.trie.TrieStore)

Aggregations

TrieStore (co.rsk.trie.TrieStore)43 Test (org.junit.Test)29 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)28 HashMapDB (org.ethereum.datasource.HashMapDB)26 Trie (co.rsk.trie.Trie)18 MutableRepository (org.ethereum.db.MutableRepository)12 BlockStore (org.ethereum.db.BlockStore)11 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)9 RepositoryLocator (co.rsk.db.RepositoryLocator)6 MultiTrieStore (co.rsk.trie.MultiTrieStore)6 Path (java.nio.file.Path)6 Repository (org.ethereum.core.Repository)6 DataWord (org.ethereum.vm.DataWord)6 MutableTrieImpl (co.rsk.db.MutableTrieImpl)5 TransactionGateway (co.rsk.net.TransactionGateway)5 World (co.rsk.test.World)5 BigInteger (java.math.BigInteger)5 ArrayList (java.util.ArrayList)5 ECKey (org.ethereum.crypto.ECKey)5 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)5