use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class LockTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minHashes = 100;
final int maxHashes = 10000;
final int minHeight = 1000;
final int maxHeight = 2000;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
int hashesToGenerate = Helper.randomInRange(minHashes, maxHashes);
int randomHashIndex = Helper.randomInRange(0, hashesToGenerate - 1);
Random rnd = new Random();
Map<Sha256Hash, Long> hashesAlreadyProcessed;
try {
hashesAlreadyProcessed = provider.getBtcTxHashesAlreadyProcessed();
} catch (IOException e) {
throw new RuntimeException("Exception trying to gather hashes already processed for benchmarking");
}
for (int i = 0; i < hashesToGenerate; i++) {
Sha256Hash hash = Sha256Hash.of(BigInteger.valueOf(rnd.nextLong()).toByteArray());
long height = Helper.randomInRange(minHeight, maxHeight);
hashesAlreadyProcessed.put(hash, height);
if (i == randomHashIndex) {
randomHashInMap = hash;
}
}
};
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class LockWhitelistTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minSize = 10;
final int maxSize = 100;
final int minBtcBlocks = 500;
final int maxBtcBlocks = 1000;
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);
lockWhitelist = provider.getLockWhitelist();
int size = Helper.randomInRange(minSize, maxSize);
for (int i = 0; i < size; i++) {
Address address = new BtcECKey().toAddress(networkParameters);
Coin value = Helper.randomCoin(Coin.COIN, 1, 30);
lockWhitelist.put(address, value);
}
};
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class StateForBtcReleaseClientTest method getInitializer.
private BridgeStorageProviderInitializer getInitializer() {
final int minNumTxs = 1;
final int maxNumTxs = 100;
final int minNumInputs = 1;
final int maxNumInputs = 10;
return (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Map<Keccak256, BtcTransaction> txsWaitingForSignatures;
try {
txsWaitingForSignatures = provider.getRskTxsWaitingForSignatures();
} catch (IOException e) {
throw new RuntimeException("Exception while trying to gather txs waiting for signatures for storage initialization");
}
int numTxs = Helper.randomInRange(minNumTxs, maxNumTxs);
for (int i = 0; i < numTxs; i++) {
BtcTransaction releaseTx = new BtcTransaction(networkParameters);
Federation federation = bridgeConstants.getGenesisFederation();
// Receiver and amounts
Address toAddress = new BtcECKey().toAddress(networkParameters);
Coin releaseAmount = Coin.CENT.multiply(Helper.randomInRange(10, 100));
releaseTx.addOutput(releaseAmount, toAddress);
// Input generation
int numInputs = Helper.randomInRange(minNumInputs, maxNumInputs);
for (int j = 0; j < numInputs; j++) {
Coin inputAmount = releaseAmount.divide(numInputs);
BtcTransaction inputTx = new BtcTransaction(networkParameters);
inputTx.addOutput(inputAmount, federation.getAddress());
releaseTx.addInput(inputTx.getOutput(0)).setScriptSig(PegTestUtils.createBaseInputScriptThatSpendsFromTheFederation(federation));
}
Keccak256 rskTxHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(new Random().nextLong()).toByteArray()));
txsWaitingForSignatures.put(rskTxHash, releaseTx);
}
};
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class UpdateCollectionsTest method updateCollections_buildReleaseTxs.
private void updateCollections_buildReleaseTxs(ExecutionStats stats, int numCases) throws IOException {
final int minUTXOs = 1;
final int maxUTXOs = 1000;
final int minMilliBtc = 1;
final int maxMilliBtc = 1000;
final int minReleaseRequests = 1;
final int maxReleaseRequests = 100;
final int minMilliReleaseBtc = 10;
final int maxMilliReleaseBtc = 2000;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Random rnd = new Random();
List<UTXO> utxos;
ReleaseRequestQueue queue;
try {
utxos = provider.getNewFederationBtcUTXOs();
} catch (Exception e) {
throw new RuntimeException("Unable to gather active federation btc utxos");
}
try {
queue = provider.getReleaseRequestQueue();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release request queue");
}
// Generate some utxos
int numUTXOs = Helper.randomInRange(minUTXOs, maxUTXOs);
Script federationScript = BridgeRegTestConstants.getInstance().getGenesisFederation().getP2SHScript();
for (int i = 0; i < numUTXOs; i++) {
Sha256Hash hash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliBtc, maxMilliBtc));
utxos.add(new UTXO(hash, 0, value, 1, false, federationScript));
}
// Generate some release requests to process
for (int i = 0; i < Helper.randomInRange(minReleaseRequests, maxReleaseRequests); i++) {
Coin value = Coin.MILLICOIN.multiply(Helper.randomInRange(minMilliReleaseBtc, maxMilliReleaseBtc));
queue.add(new BtcECKey().toAddress(parameters), value);
}
};
final byte[] updateCollectionsEncoded = Bridge.UPDATE_COLLECTIONS.encode();
ABIEncoder abiEncoder = (int executionIndex) -> updateCollectionsEncoded;
executeAndAverage("updateCollections-releaseRequests", numCases, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
}
use of co.rsk.peg.BridgeStorageProvider in project rskj by rsksmart.
the class UpdateCollectionsTest method updateCollections_confirmTxs.
private void updateCollections_confirmTxs(ExecutionStats stats, int numCases) throws IOException {
final int minTxsWaitingForSigs = 0;
final int maxTxsWaitingForSigs = 10;
final int minReleaseTxs = 1;
final int maxReleaseTxs = 100;
final int minBlockNumber = 10;
final int maxBlockNumber = 100;
final int minHeight = 50;
final int maxHeight = 150;
final int minCentOutput = 1;
final int maxCentOutput = 100;
final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
Random rnd = new Random();
SortedMap<Keccak256, BtcTransaction> txsWaitingForSignatures;
ReleaseTransactionSet txSet;
try {
txsWaitingForSignatures = provider.getRskTxsWaitingForSignatures();
} catch (Exception e) {
throw new RuntimeException("Unable to gather txs waiting for signatures");
}
try {
txSet = provider.getReleaseTransactionSet();
} catch (Exception e) {
throw new RuntimeException("Unable to gather release tx set");
}
// Generate some txs waiting for signatures
Script genesisFederationScript = bridgeConstants.getGenesisFederation().getP2SHScript();
for (int i = 0; i < Helper.randomInRange(minTxsWaitingForSigs, maxTxsWaitingForSigs); i++) {
Keccak256 rskHash = new Keccak256(HashUtil.keccak256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
txsWaitingForSignatures.put(rskHash, btcTx);
}
// Generate some txs waiting for confirmations
for (int i = 0; i < Helper.randomInRange(minReleaseTxs, maxReleaseTxs); i++) {
BtcTransaction btcTx = new BtcTransaction(networkParameters);
Sha256Hash inputHash = Sha256Hash.wrap(HashUtil.sha256(BigInteger.valueOf(rnd.nextLong()).toByteArray()));
btcTx.addInput(inputHash, 0, genesisFederationScript);
btcTx.addOutput(Helper.randomCoin(Coin.CENT, minCentOutput, maxCentOutput), new BtcECKey());
long blockNumber = Helper.randomInRange(minBlockNumber, maxBlockNumber);
txSet.add(btcTx, blockNumber);
}
};
final byte[] updateCollectionsEncoded = Bridge.UPDATE_COLLECTIONS.encode();
ABIEncoder abiEncoder = (int executionIndex) -> updateCollectionsEncoded;
HeightProvider heightProvider = (int executionIndex) -> Helper.randomInRange(minHeight, maxHeight);
executeAndAverage("updateCollections-releaseTxs", numCases, abiEncoder, storageInitializer, Helper.getZeroValueRandomSenderTxBuilder(), heightProvider, stats);
}
Aggregations