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);
}
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;
}
Aggregations