use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class ActiveFederationTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer(boolean genesis) {
final int minFederators = 10;
final int maxFederators = 16;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
if (!genesis) {
int numFederators = Helper.randomInRange(minFederators, maxFederators);
List<BtcECKey> federatorKeys = new ArrayList<>();
for (int i = 0; i < numFederators; i++) {
federatorKeys.add(new BtcECKey());
}
federation = new Federation(federatorKeys, Instant.ofEpochMilli(new Random().nextLong()), Helper.randomInRange(1, 10), networkParameters);
provider.setNewFederation(federation);
} else {
federation = bridgeConstants.getGenesisFederation();
}
};
}
use of co.rsk.peg.BridgeStorageProvider 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;
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class BtcBlockchainTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minBtcBlocks = 1000;
final int maxBtcBlocks = 2000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
};
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class ReceiveHeadersTest method receiveHeaders.
@Test
public void receiveHeaders() throws IOException {
final int minBtcBlocks = 1000;
final int maxBtcBlocks = 2000;
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
BtcBlockStore btcBlockStore = new RepositoryBlockStore(new RskSystemProperties(), repository, PrecompiledContracts.BRIDGE_ADDR);
Context btcContext = new Context(networkParameters);
BtcBlockChain btcBlockChain;
try {
btcBlockChain = new BtcBlockChain(btcContext, btcBlockStore);
} catch (BlockStoreException e) {
throw new RuntimeException("Error initializing btc blockchain for tests");
}
int blocksToGenerate = Helper.randomInRange(minBtcBlocks, maxBtcBlocks);
BtcBlock lastBlock = Helper.generateAndAddBlocks(btcBlockChain, blocksToGenerate);
blockToTry = Helper.generateBtcBlock(lastBlock);
};
ABIEncoder abiEncoder = (int executionIndex) -> {
List<BtcBlock> headersToSendToBridge = new ArrayList<>();
// Send just one header (that's the only case we're interested in measuring atm
headersToSendToBridge.add(blockToTry);
Object[] headersEncoded = headersToSendToBridge.stream().map(h -> h.bitcoinSerialize()).toArray();
return Bridge.RECEIVE_HEADERS.encode(new Object[] { headersEncoded });
};
ExecutionStats stats = new ExecutionStats("receiveHeaders");
executeAndAverage("receiveHeaders", 200, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
BridgePerformanceTest.addStats(stats);
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class ReleaseBtcTest method releaseBtc.
@Test
public void releaseBtc() throws IOException {
int minCentsBtc = 5;
int maxCentsBtc = 100;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
ReleaseRequestQueue queue;
try {
queue = provider.getReleaseRequestQueue();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release request queue");
}
for (int i = 0; i < Helper.randomInRange(10, 100); i++) {
Coin value = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc));
queue.add(new BtcECKey().toAddress(parameters), value);
}
};
final byte[] releaseBtcEncoded = Bridge.RELEASE_BTC.encode();
ABIEncoder abiEncoder = (int executionIndex) -> releaseBtcEncoded;
TxBuilder txBuilder = (int executionIndex) -> {
long satoshis = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc)).getValue();
BigInteger weis = Denomination.satoshisToWeis(BigInteger.valueOf(satoshis));
ECKey sender = new ECKey();
return Helper.buildSendValueTx(sender, weis);
};
ExecutionStats stats = new ExecutionStats("releaseBtc");
executeAndAverage("releaseBtc", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats);
BridgePerformanceTest.addStats(stats);
}
Aggregations