Search in sources :

Example 26 with TrieStore

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

the class BlockExecutorTest method generateBlockWithOneStrangeTransaction.

public TestObjects generateBlockWithOneStrangeTransaction(int strangeTransactionType) {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = new MutableRepository(trieStore, new Trie(trieStore));
    Repository track = repository.startTracking();
    Account account = createAccount("acctest1", track, Coin.valueOf(30000));
    Account account2 = createAccount("acctest2", track, Coin.valueOf(10L));
    track.commit();
    Assert.assertFalse(Arrays.equals(EMPTY_TRIE_HASH, repository.getRoot()));
    BlockExecutor executor = buildBlockExecutor(trieStore);
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = createStrangeTransaction(account, account2, BigInteger.TEN, repository.getNonce(account.getAddress()), strangeTransactionType);
    txs.add(tx);
    List<BlockHeader> uncles = new ArrayList<>();
    Block genesis = BlockChainImplTest.getGenesisBlock(trieStore);
    genesis.setStateRoot(repository.getRoot());
    Block block = new BlockGenerator().createChildBlock(genesis, txs, uncles, 1, null);
    // Forces all transactions included
    executor.executeAndFillReal(block, genesis.getHeader());
    repository.save();
    return new TestObjects(trieStore, block, genesis, tx, account);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) MutableRepository(org.ethereum.db.MutableRepository) MutableRepository(org.ethereum.db.MutableRepository) Trie(co.rsk.trie.Trie)

Example 27 with TrieStore

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

the class NetworkStateExporterTest method setup.

@Before
public void setup() {
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    MutableTrieImpl mutableTrie = new MutableTrieImpl(trieStore, new Trie(trieStore));
    repository = new MutableRepository(mutableTrie);
    blockchain = mock(Blockchain.class);
    block = mock(Block.class);
    when(blockchain.getBestBlock()).thenReturn(block);
    BlockHeader blockHeader = mock(BlockHeader.class);
    when(block.getHeader()).thenReturn(blockHeader);
    RepositoryLocator repositoryLocator = mock(RepositoryLocator.class);
    when(repositoryLocator.snapshotAt(block.getHeader())).thenReturn(new MutableRepository(mutableTrie));
    this.nse = new NetworkStateExporter(repositoryLocator, blockchain);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) MutableRepository(org.ethereum.db.MutableRepository) Blockchain(org.ethereum.core.Blockchain) Block(org.ethereum.core.Block) MutableTrieImpl(co.rsk.db.MutableTrieImpl) HashMapDB(org.ethereum.datasource.HashMapDB) BlockHeader(org.ethereum.core.BlockHeader) TrieStore(co.rsk.trie.TrieStore) Trie(co.rsk.trie.Trie) Before(org.junit.Before)

Example 28 with TrieStore

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

the class ShowStateInfo method onExecute.

@Override
protected void onExecute(@Nonnull String[] args, @Nonnull RskContext ctx) throws Exception {
    BlockStore blockStore = ctx.getBlockStore();
    TrieStore trieStore = ctx.getTrieStore();
    printStateInfo(args, blockStore, trieStore);
}
Also used : BlockStore(org.ethereum.db.BlockStore) TrieStore(co.rsk.trie.TrieStore)

Example 29 with TrieStore

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

the class RskContextTest method shouldBuildMultiTrieStoreMigratingSingleTrieStore.

@Test
public void shouldBuildMultiTrieStoreMigratingSingleTrieStore() throws IOException {
    rskContext.close();
    long numberOfEpochs = 3;
    Path testDatabasesDirectory = databaseDir.toPath();
    doReturn(new GarbageCollectorConfig(true, 1000, (int) numberOfEpochs)).when(testProperties).garbageCollectorConfig();
    rskContext = makeRskContext();
    TrieStore trieStore = rskContext.getTrieStore();
    assertThat(trieStore, is(instanceOf(MultiTrieStore.class)));
    assertThat(Files.list(testDatabasesDirectory).count(), is(numberOfEpochs));
    assertThat(Files.list(testDatabasesDirectory).noneMatch(p -> p.getFileName().toString().equals("unitrie")), is(true));
}
Also used : Path(java.nio.file.Path) IntStream(java.util.stream.IntStream) NodeBlockProcessor(co.rsk.net.NodeBlockProcessor) co.rsk.config(co.rsk.config) HashSet(java.util.HashSet) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) Method(java.lang.reflect.Method) Path(java.nio.file.Path) TrieStore(co.rsk.trie.TrieStore) Before(org.junit.Before) Files(java.nio.file.Files) AsyncNodeBlockProcessor(co.rsk.net.AsyncNodeBlockProcessor) MultiTrieStore(co.rsk.trie.MultiTrieStore) Set(java.util.Set) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) RskTestContext(org.ethereum.util.RskTestContext) Paths(java.nio.file.Paths) Matchers.contains(org.hamcrest.Matchers.contains) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) Modifier(java.lang.reflect.Modifier) Genesis(org.ethereum.core.Genesis) Assert(org.junit.Assert) ConsensusRule(org.ethereum.config.blockchain.upgrades.ConsensusRule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) TrieStore(co.rsk.trie.TrieStore) MultiTrieStore(co.rsk.trie.MultiTrieStore) Test(org.junit.Test)

Example 30 with TrieStore

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

the class RskContextTest method shouldBuildMultiTrieStore.

@Test
public void shouldBuildMultiTrieStore() throws IOException {
    long numberOfEpochs = 3;
    Path testDatabasesDirectory = databaseDir.toPath();
    doReturn(new GarbageCollectorConfig(true, 1000, (int) numberOfEpochs)).when(testProperties).garbageCollectorConfig();
    TrieStore trieStore = rskContext.getTrieStore();
    assertThat(trieStore, is(instanceOf(MultiTrieStore.class)));
    assertThat(Files.list(testDatabasesDirectory).count(), is(numberOfEpochs));
}
Also used : Path(java.nio.file.Path) TrieStore(co.rsk.trie.TrieStore) MultiTrieStore(co.rsk.trie.MultiTrieStore) 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