Search in sources :

Example 36 with TrieStore

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

the class RskTestFactory method getGenesisInstance.

public static Genesis getGenesisInstance(RskSystemProperties config) {
    boolean useRskip92Encoding = config.getActivationConfig().isActive(ConsensusRule.RSKIP92, 0L);
    boolean isRskip126Enabled = config.getActivationConfig().isActive(ConsensusRule.RSKIP126, 0L);
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    return new TestGenesisLoader(trieStore, config.genesisInfo(), config.getNetworkConstants().getInitialNonce(), false, useRskip92Encoding, isRskip126Enabled).load();
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader)

Example 37 with TrieStore

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

the class ContractDetailsImplTest method syncStorageWithExternalStorage.

@Test
public void syncStorageWithExternalStorage() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Trie trie = new TrieImpl(store, false);
    byte[] accountAddress = randomAddress();
    ContractDetailsImpl details = new ContractDetailsImpl(config, accountAddress, trie, null);
    int nkeys = IN_MEMORY_STORAGE_LIMIT;
    for (int k = 1; k <= nkeys + 1; k++) details.put(new DataWord(k), new DataWord(k * 2));
    Assert.assertTrue(details.hasExternalStorage());
    details.syncStorage();
    int ssize = details.getStorageSize();
    details = new ContractDetailsImpl(config, details.getEncoded());
    Assert.assertEquals(ssize, details.getStorageSize());
    for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(details.get(new DataWord(k)));
    ContractDetailsImpl clone = new ContractDetailsImpl(config, details.getEncoded());
    Assert.assertNotNull(clone);
    Assert.assertTrue(clone.hasExternalStorage());
    Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
    for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(clone.get(new DataWord(k)));
    for (int k = 1; k <= nkeys + 1; k++) clone.put(new DataWord(k), new DataWord(k * 3));
    Assert.assertTrue(clone.hasExternalStorage());
    Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
    ContractDetailsImpl snapshot = (ContractDetailsImpl) clone.getSnapshotTo(clone.getStorageHash());
    Assert.assertTrue(snapshot.hasExternalStorage());
    Assert.assertEquals(clone.getStorageSize(), snapshot.getStorageSize());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) TrieImpl(co.rsk.trie.TrieImpl) DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 38 with TrieStore

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

the class ContractDetailsImplTest method syncStorageAndGetKeyValues.

@Test
public void syncStorageAndGetKeyValues() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Trie trie = new TrieImpl(store, false);
    byte[] accountAddress = randomAddress();
    ContractDetailsImpl details = new ContractDetailsImpl(config, accountAddress, trie, null);
    int nkeys = IN_MEMORY_STORAGE_LIMIT;
    for (int k = 1; k <= nkeys + 1; k++) details.put(new DataWord(k), new DataWord(k * 2));
    Assert.assertTrue(details.hasExternalStorage());
    details.syncStorage();
    for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(details.get(new DataWord(k)));
    ContractDetailsImpl clone = new ContractDetailsImpl(config, details.getEncoded());
    Assert.assertNotNull(clone);
    Assert.assertTrue(clone.hasExternalStorage());
    Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
    for (int k = 1; k <= nkeys + 1; k++) Assert.assertNotNull(clone.get(new DataWord(k)));
    for (int k = 1; k <= nkeys + 1; k++) clone.put(new DataWord(k), new DataWord(k * 3));
    Assert.assertTrue(clone.hasExternalStorage());
    Assert.assertEquals(details.getStorageSize(), clone.getStorageSize());
    ContractDetailsImpl snapshot = (ContractDetailsImpl) clone.getSnapshotTo(clone.getStorageHash());
    Assert.assertTrue(snapshot.hasExternalStorage());
    Assert.assertEquals(clone.getStorageSize(), snapshot.getStorageSize());
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) TrieImpl(co.rsk.trie.TrieImpl) DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 39 with TrieStore

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

the class ContractDetailsImplTest method syncStorageInDetailsWithTrieInMemory.

@Test
public void syncStorageInDetailsWithTrieInMemory() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Trie trie = new TrieImpl(store, false);
    byte[] accountAddress = randomAddress();
    ContractDetailsImpl details = new ContractDetailsImpl(config, accountAddress, trie, null);
    details.put(new DataWord(42), DataWord.ONE);
    details.syncStorage();
    Assert.assertNotNull(details.get(new DataWord(42)));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) TrieImpl(co.rsk.trie.TrieImpl) DataWord(org.ethereum.vm.DataWord) TestUtils.randomDataWord(org.ethereum.TestUtils.randomDataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 40 with TrieStore

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

the class RepositoryImplOriginalTest method test20.

// testing for snapshot
@Test
public void test20() {
    TrieStore store = new TrieStoreImpl(new HashMapDB());
    Repository repository = new RepositoryImpl(config, store);
    byte[] root = repository.getRoot();
    DataWord cowKey1 = new DataWord("c1");
    DataWord cowKey2 = new DataWord("c2");
    DataWord cowVal1 = new DataWord("c0a1");
    DataWord cowVal0 = new DataWord("c0a0");
    DataWord horseKey1 = new DataWord("e1");
    DataWord horseKey2 = new DataWord("e2");
    DataWord horseVal1 = new DataWord("c0a1");
    DataWord horseVal0 = new DataWord("c0a0");
    // track
    Repository track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey1, cowVal1);
    track2.addStorageRow(HORSE, horseKey1, horseVal1);
    track2.commit();
    byte[] root2 = repository.getRoot();
    // track
    track2 = repository.startTracking();
    track2.addStorageRow(COW, cowKey2, cowVal0);
    track2.addStorageRow(HORSE, horseKey2, horseVal0);
    track2.commit();
    byte[] root3 = repository.getRoot();
    Repository snapshot = repository.getSnapshotTo(root);
    ContractDetails cowDetails = snapshot.getContractDetails(COW);
    ContractDetails horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(null, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(null, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root2);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(null, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(null, horseDetails.get(horseKey2));
    snapshot = repository.getSnapshotTo(root3);
    cowDetails = snapshot.getContractDetails(COW);
    horseDetails = snapshot.getContractDetails(HORSE);
    assertEquals(cowVal1, cowDetails.get(cowKey1));
    assertEquals(cowVal0, cowDetails.get(cowKey2));
    assertEquals(horseVal1, horseDetails.get(horseKey1));
    assertEquals(horseVal0, horseDetails.get(horseKey2));
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Repository(org.ethereum.core.Repository) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) ContractDetails(org.ethereum.db.ContractDetails) Test(org.junit.Test)

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