Search in sources :

Example 26 with TrieStoreImpl

use of co.rsk.trie.TrieStoreImpl 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 27 with TrieStoreImpl

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

the class RepositoryBuilder method build.

public static Repository build(Map<String, AccountTck> accounts) {
    HashMap<RskAddress, AccountState> stateBatch = new HashMap<>();
    HashMap<RskAddress, ContractDetails> detailsBatch = new HashMap<>();
    for (String address : accounts.keySet()) {
        RskAddress addr = new RskAddress(address);
        AccountTck accountTCK = accounts.get(address);
        AccountBuilder.StateWrap stateWrap = AccountBuilder.build(accountTCK);
        AccountState state = stateWrap.getAccountState();
        ContractDetails details = stateWrap.getContractDetails();
        stateBatch.put(addr, state);
        ContractDetailsCacheImpl detailsCache = new ContractDetailsCacheImpl(details);
        detailsCache.setDirty(true);
        detailsBatch.put(addr, detailsCache);
    }
    RepositoryImpl repositoryDummy = new RepositoryImpl(new RskSystemProperties(), new TrieStoreImpl(new HashMapDB()));
    Repository track = repositoryDummy.startTracking();
    track.updateBatch(stateBatch, detailsBatch);
    track.commit();
    return repositoryDummy;
}
Also used : AccountTck(org.ethereum.jsontestsuite.model.AccountTck) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) HashMap(java.util.HashMap) AccountState(org.ethereum.core.AccountState) HashMapDB(org.ethereum.datasource.HashMapDB) ContractDetails(org.ethereum.db.ContractDetails) Repository(org.ethereum.core.Repository) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) ContractDetailsCacheImpl(org.ethereum.db.ContractDetailsCacheImpl) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 28 with TrieStoreImpl

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

the class RskTestFactory method getRepository.

public Repository getRepository() {
    if (repository == null) {
        HashMapDB stateStore = new HashMapDB();
        repository = new RepositoryImpl(config, new TrieStoreImpl(stateStore));
    }
    return repository;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) HashMapDB(org.ethereum.datasource.HashMapDB)

Example 29 with TrieStoreImpl

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

the class BlockChainBuilder method build.

public BlockChainImpl build(boolean withoutCleaner) {
    if (repository == null)
        repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
    if (blockStore == null) {
        blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    }
    if (receiptStore == null) {
        KeyValueDataSource ds = new HashMapDB();
        ds.init();
        receiptStore = new ReceiptStoreImpl(ds);
    }
    if (txinfos != null && !txinfos.isEmpty())
        for (TransactionInfo txinfo : txinfos) receiptStore.add(txinfo.getBlockHash(), txinfo.getIndex(), txinfo.getReceipt());
    EthereumListener listener = new BlockExecutorTest.SimpleEthereumListener();
    BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
    validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).blockStore(blockStore);
    BlockValidator blockValidator = validatorBuilder.build();
    if (this.adminInfo == null)
        this.adminInfo = new AdminInfo();
    BlockChainImpl blockChain = new BlockChainImpl(config, this.repository, this.blockStore, receiptStore, null, listener, this.adminInfo, blockValidator);
    if (this.testing) {
        blockChain.setBlockValidator(new DummyBlockValidator());
        blockChain.setNoValidation(true);
    }
    TransactionPoolImpl transactionPool;
    if (withoutCleaner) {
        transactionPool = new TransactionPoolImplNoCleaner(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    } else {
        transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
    }
    blockChain.setTransactionPool(transactionPool);
    if (this.genesis != null) {
        for (RskAddress addr : this.genesis.getPremine().keySet()) {
            this.repository.createAccount(addr);
            this.repository.addBalance(addr, this.genesis.getPremine().get(addr).getAccountState().getBalance());
        }
        Repository track = this.repository.startTracking();
        new RepositoryBlockStore(config, track, PrecompiledContracts.BRIDGE_ADDR);
        track.commit();
        this.genesis.setStateRoot(this.repository.getRoot());
        this.genesis.flushRLP();
        blockChain.setBestBlock(this.genesis);
        blockChain.setTotalDifficulty(this.genesis.getCumulativeDifficulty());
    }
    if (this.blocks != null) {
        BlockExecutor blockExecutor = new BlockExecutor(config, repository, receiptStore, blockStore, listener);
        for (Block b : this.blocks) {
            blockExecutor.executeAndFillAll(b, blockChain.getBestBlock());
            blockChain.tryToConnect(b);
        }
    }
    return blockChain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) HashMap(java.util.HashMap) AdminInfo(org.ethereum.manager.AdminInfo) HashMapDB(org.ethereum.datasource.HashMapDB) BlockValidator(co.rsk.validators.BlockValidator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) RepositoryImpl(co.rsk.db.RepositoryImpl) RepositoryBlockStore(co.rsk.peg.RepositoryBlockStore) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource)

Example 30 with TrieStoreImpl

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

TrieStoreImpl (co.rsk.trie.TrieStoreImpl)38 HashMapDB (org.ethereum.datasource.HashMapDB)34 TrieStore (co.rsk.trie.TrieStore)25 Trie (co.rsk.trie.Trie)21 Test (org.junit.Test)20 MutableRepository (org.ethereum.db.MutableRepository)12 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)8 RskAddress (co.rsk.core.RskAddress)8 DataWord (org.ethereum.vm.DataWord)8 TrieImpl (co.rsk.trie.TrieImpl)7 Repository (org.ethereum.core.Repository)7 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)7 RepositoryImpl (co.rsk.db.RepositoryImpl)6 ArrayList (java.util.ArrayList)6 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)6 MutableTrieImpl (co.rsk.db.MutableTrieImpl)5 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)5 RskSystemProperties (co.rsk.config.RskSystemProperties)4 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)4 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)4