Search in sources :

Example 51 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class TransactionModuleTest method sendRawTransactionWithoutAutoMining.

@Test
public void sendRawTransactionWithoutAutoMining() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    BlockChainImpl blockchain = world.getBlockChain();
    TrieStore trieStore = world.getTrieStore();
    RepositoryLocator repositoryLocator = world.getRepositoryLocator();
    BlockStore blockStore = world.getBlockStore();
    TransactionPool transactionPool = new TransactionPoolImpl(config, repositoryLocator, blockStore, blockFactory, null, buildTransactionExecutorFactory(blockStore, receiptStore, world.getBlockTxSignatureCache()), world.getReceivedTxSignatureCache(), 10, 100);
    TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
    Web3Impl web3 = createEnvironment(blockchain, receiptStore, trieStore, transactionPool, blockStore, false, world.getBlockTxSignatureCache(), transactionGateway);
    String txHash = sendRawTransaction(web3);
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    Assert.assertEquals(1, transactionPool.getPendingTransactions().size());
    Assert.assertEquals(txHash, transactionPool.getPendingTransactions().get(0).getHash().toJsonString());
}
Also used : BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) TrieStore(co.rsk.trie.TrieStore) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Example 52 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BridgePerformanceTestCase method executeAndAverage.

protected ExecutionStats executeAndAverage(String name, int times, ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, ExecutionStats stats, ResultCallback resultCallback, PostInitCallback postInitCallback) throws VMException {
    EnvironmentBuilder environmentBuilder = new EnvironmentBuilder() {

        private Bridge bridge;

        private RepositoryTrackWithBenchmarking benchmarkerTrack;

        private BridgeStorageProvider storageProvider;

        private TrieStore createTrieStore() {
            return new TrieStoreImpl(new HashMapDB());
        }

        @Override
        public Environment build(int executionIndex, TxBuilder txBuilder, int height) throws VMException {
            TrieStore trieStore = createTrieStore();
            Trie trie = new Trie(trieStore);
            benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, trie);
            Repository repository = benchmarkerTrack.startTracking();
            storageProvider = new BridgeStorageProvider(repository, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, activationConfig.forBlock((long) executionIndex));
            BtcBlockStore btcBlockStore = btcBlockStoreFactory.newInstance(repository, bridgeConstants, storageProvider, activationConfig.forBlock((long) executionIndex));
            storageInitializer.initialize(storageProvider, repository, executionIndex, btcBlockStore);
            repository.addBalance(PrecompiledContracts.BRIDGE_ADDR, co.rsk.core.Coin.fromBitcoin(Coin.COIN.multiply(21_000_000L)));
            try {
                storageProvider.save();
            } catch (Exception e) {
                throw new RuntimeException("Error trying to save the storage after initialization", e);
            }
            repository.commit();
            benchmarkerTrack.commit();
            benchmarkerTrack = new RepositoryTrackWithBenchmarking(trieStore, benchmarkerTrack.getTrie());
            List<LogInfo> logs = new ArrayList<>();
            // TODO: This was commented to make registerBtcCoinbaseTransactionTest & getBtcTransactionConfirmationTest work.
            // Cache is not being populated.
            // Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(
            // constants.getBridgeConstants().getBtcParams());
            BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, constants.getBridgeConstants(), activationConfig);
            bridge = new Bridge(PrecompiledContracts.BRIDGE_ADDR, constants, activationConfig, bridgeSupportFactory);
            BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
            Blockchain blockchain = blockChainBuilder.ofSize(height);
            Transaction tx = txBuilder.build(executionIndex);
            bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockChainBuilder.getBlockStore(), null, logs);
            // Execute a random method so that bridge support initialization
            // does its initial writes to the repo for e.g. genesis block,
            // federation, etc, etc. and we don't get
            // those recorded in the actual execution.
            boolean oldLocalCall = tx.isLocalCallTransaction();
            tx.setLocalCallTransaction(true);
            bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
            tx.setLocalCallTransaction(oldLocalCall);
            benchmarkerTrack.getStatistics().clear();
            Environment environment = new Environment() {

                @Override
                public PrecompiledContracts.PrecompiledContract getContract() {
                    return bridge;
                }

                @Override
                public BenchmarkedRepository getBenchmarkedRepository() {
                    return benchmarkerTrack;
                }

                @Override
                public void finalise() {
                    benchmarkerTrack.commit();
                }
            };
            if (postInitCallback != null) {
                postInitCallback.afterInit(environment);
            }
            return environment;
        }
    };
    return super.executeAndAverage(name, times, environmentBuilder, abiEncoder, txBuilder, heightProvider, stats, resultCallback);
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) LogInfo(org.ethereum.vm.LogInfo) Blockchain(org.ethereum.core.Blockchain) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) TrieStore(co.rsk.trie.TrieStore) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) RepositoryTrackWithBenchmarking(co.rsk.db.RepositoryTrackWithBenchmarking) VMException(org.ethereum.vm.exception.VMException) BenchmarkedRepository(co.rsk.db.BenchmarkedRepository) Repository(org.ethereum.core.Repository) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) InternalTransaction(org.ethereum.vm.program.InternalTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Example 53 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class RemascProcessMinerFeesTest method setup.

@Before
public void setup() {
    blockFactory = new BlockFactory(config.getActivationConfig());
    stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    blockchainBuilder = new BlockChainBuilder().setStateRootHandler(stateRootHandler).setGenesis(genesisBlock).setConfig(config).setTesting(true);
}
Also used : StateRootHandler(co.rsk.db.StateRootHandler) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) HashMapDB(org.ethereum.datasource.HashMapDB) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) Before(org.junit.Before)

Example 54 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockChainBuilder method build.

public BlockChainImpl build() {
    BlocksIndex blocksIndex = new HashMapBlocksIndex();
    if (config == null) {
        config = new TestSystemProperties();
    }
    if (trieStore == null) {
        trieStore = new TrieStoreImpl(new HashMapDB().setClearOnClose(false));
    }
    if (repository == null) {
        repository = new MutableRepository(trieStore, new Trie(trieStore));
    }
    if (stateRootHandler == null) {
        stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    }
    if (genesis == null) {
        genesis = new BlockGenerator().getGenesisBlock();
    }
    GenesisLoaderImpl.loadGenesisInitalState(repository, genesis);
    repository.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    if (blockStore == null) {
        blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), blocksIndex);
    }
    if (receiptStore == null) {
        KeyValueDataSource ds = new HashMapDB();
        ds.init();
        receiptStore = new ReceiptStoreImpl(ds);
    }
    if (listener == null) {
        listener = new BlockExecutorTest.SimpleEthereumListener();
    }
    if (bridgeSupportFactory == null) {
        bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    }
    BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
    validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(trieStore).blockStore(blockStore);
    BlockValidator blockValidator = validatorBuilder.build();
    ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
    repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    transactionPool = new TransactionPoolImpl(config, repositoryLocator, this.blockStore, blockFactory, new TestCompositeEthereumListener(), transactionExecutorFactory, new ReceivedTxSignatureCache(), 10, 100);
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory);
    BlockChainImpl blockChain = new BlockChainLoader(blockStore, receiptStore, transactionPool, listener, blockValidator, blockExecutor, genesis, stateRootHandler, repositoryLocator).loadBlockchain();
    if (this.testing) {
        blockChain.setBlockValidator(new DummyBlockValidator());
        blockChain.setNoValidation(true);
    }
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    if (this.blocks != null) {
        for (Block b : this.blocks) {
            blockExecutor.executeAndFillAll(b, blockChain.getBestBlock().getHeader());
            blockChain.tryToConnect(b);
        }
    }
    return blockChain;
}
Also used : BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockValidator(co.rsk.validators.BlockValidator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) Trie(co.rsk.trie.Trie) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) BlockChainLoader(org.ethereum.core.genesis.BlockChainLoader) HashMapDB(org.ethereum.datasource.HashMapDB) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 55 with HashMapDB

use of org.ethereum.datasource.HashMapDB in project rskj by rsksmart.

the class BlockBuilder method build.

public Block build() {
    Block block = blockGenerator.createChildBlock(parent, txs, uncles, difficulty, this.minGasPrice, gasLimit);
    if (blockChain != null) {
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
        executor.executeAndFill(block, parent.getHeader());
    }
    return block;
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) TestSystemProperties(co.rsk.config.TestSystemProperties)

Aggregations

HashMapDB (org.ethereum.datasource.HashMapDB)208 Test (org.junit.Test)181 World (co.rsk.test.World)45 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)34 ReceiptStore (org.ethereum.db.ReceiptStore)34 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)34 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)29 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)27 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)27 TrieStore (co.rsk.trie.TrieStore)26 HashMapBlocksIndex (co.rsk.db.HashMapBlocksIndex)23 Trie (co.rsk.trie.Trie)21 Blockchain (org.ethereum.core.Blockchain)17 RskAddress (co.rsk.core.RskAddress)16 Transaction (org.ethereum.core.Transaction)16 DslParser (co.rsk.test.dsl.DslParser)15 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)13 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)12