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