Search in sources :

Example 1 with RepositoryTrackWithBenchmarking

use of co.rsk.db.RepositoryTrackWithBenchmarking 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 2 with RepositoryTrackWithBenchmarking

use of co.rsk.db.RepositoryTrackWithBenchmarking in project rskj by rsksmart.

the class BridgePerformanceTestCase method execute.

private ExecutionTracker execute(ABIEncoder abiEncoder, BridgeStorageProviderInitializer storageInitializer, TxBuilder txBuilder, HeightProvider heightProvider, int executionIndex) {
    ExecutionTracker executionInfo = new ExecutionTracker(thread);
    RepositoryImpl repository = new RepositoryImpl(config);
    Repository track = repository.startTracking();
    BridgeStorageProvider storageProvider = new BridgeStorageProvider(track, PrecompiledContracts.BRIDGE_ADDR, bridgeConstants);
    storageInitializer.initialize(storageProvider, track, executionIndex);
    try {
        storageProvider.save();
    } catch (Exception e) {
        throw new RuntimeException("Error trying to save the storage after initialization", e);
    }
    track.commit();
    Transaction tx = txBuilder.build(executionIndex);
    List<LogInfo> logs = new ArrayList<>();
    RepositoryTrackWithBenchmarking benchmarkerTrack = new RepositoryTrackWithBenchmarking(config, repository);
    Bridge bridge = new Bridge(config, PrecompiledContracts.BRIDGE_ADDR);
    Blockchain blockchain = BlockChainBuilder.ofSizeWithNoTransactionPoolCleaner(heightProvider.getHeight(executionIndex));
    bridge.init(tx, blockchain.getBestBlock(), benchmarkerTrack, blockchain.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.
    bridge.execute(Bridge.GET_FEDERATION_SIZE.encode());
    benchmarkerTrack.getStatistics().clear();
    executionInfo.startTimer();
    bridge.execute(abiEncoder.encode(executionIndex));
    executionInfo.endTimer();
    benchmarkerTrack.commit();
    executionInfo.setRepositoryStatistics(benchmarkerTrack.getStatistics());
    return executionInfo;
}
Also used : LogInfo(org.ethereum.vm.LogInfo) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) Blockchain(org.ethereum.core.Blockchain) ArrayList(java.util.ArrayList) RepositoryTrackWithBenchmarking(co.rsk.db.RepositoryTrackWithBenchmarking) Repository(org.ethereum.core.Repository) Transaction(org.ethereum.core.Transaction) RepositoryImpl(co.rsk.db.RepositoryImpl) Bridge(co.rsk.peg.Bridge)

Aggregations

RepositoryTrackWithBenchmarking (co.rsk.db.RepositoryTrackWithBenchmarking)2 Blockchain (org.ethereum.core.Blockchain)2 Repository (org.ethereum.core.Repository)2 Transaction (org.ethereum.core.Transaction)2 LogInfo (org.ethereum.vm.LogInfo)2 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)1 BenchmarkedRepository (co.rsk.db.BenchmarkedRepository)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 Bridge (co.rsk.peg.Bridge)1 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)1 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)1 Trie (co.rsk.trie.Trie)1 TrieStore (co.rsk.trie.TrieStore)1 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)1 ArrayList (java.util.ArrayList)1 HashMapDB (org.ethereum.datasource.HashMapDB)1 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)1 VMException (org.ethereum.vm.exception.VMException)1 InternalTransaction (org.ethereum.vm.program.InternalTransaction)1