Search in sources :

Example 21 with TrieImpl

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

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashBaseCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 22 with TrieImpl

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

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashRecursionCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonShouldBringSameHashRecursionCase() {
    Trie trie1 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("ro"), "4".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 23 with TrieImpl

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

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashBaseCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevaltroosevaltroosevalt"), "42434445".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 24 with TrieImpl

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

the class TrieImplHashTest method sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashRecursionCase.

@Test
public void sonWithNoSiblingsAndOnlyOneSonWithSonsShouldBringSameHashRecursionCase() {
    Trie trie1 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevalt", "4243".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("ro", "4".getBytes()).put("roose", "42".getBytes()).put("roosevaltroosevalt", "424344".getBytes()).put("roosevaltroosevaltroosevaltroosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("ro"), "4".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roose"), "42".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevaltroosevaltroosevalt"), "42434445".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 25 with TrieImpl

use of co.rsk.trie.TrieImpl 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

TrieImpl (co.rsk.trie.TrieImpl)25 Trie (co.rsk.trie.Trie)22 Test (org.junit.Test)20 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)7 DataWord (org.ethereum.vm.DataWord)7 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6 HashMapDB (org.ethereum.datasource.HashMapDB)6 TrieStore (co.rsk.trie.TrieStore)5 RskAddress (co.rsk.core.RskAddress)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 Coin (co.rsk.core.Coin)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 BigInteger (java.math.BigInteger)1 Set (java.util.Set)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1 Transaction (org.ethereum.core.Transaction)1 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)1 ContractDetails (org.ethereum.db.ContractDetails)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1