Search in sources :

Example 1 with ReleaseRequestQueue

use of co.rsk.peg.ReleaseRequestQueue 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);
}
Also used : Script(co.rsk.bitcoinj.script.Script) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) ReleaseRequestQueue(co.rsk.peg.ReleaseRequestQueue) IOException(java.io.IOException) Repository(org.ethereum.core.Repository) Random(java.util.Random) List(java.util.List)

Example 2 with ReleaseRequestQueue

use of co.rsk.peg.ReleaseRequestQueue 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);
}
Also used : NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ECKey(org.ethereum.crypto.ECKey) ReleaseRequestQueue(co.rsk.peg.ReleaseRequestQueue) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) IOException(java.io.IOException) Coin(co.rsk.bitcoinj.core.Coin) Repository(org.ethereum.core.Repository) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Aggregations

BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)2 ReleaseRequestQueue (co.rsk.peg.ReleaseRequestQueue)2 IOException (java.io.IOException)2 Repository (org.ethereum.core.Repository)2 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)1 Coin (co.rsk.bitcoinj.core.Coin)1 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)1 Script (co.rsk.bitcoinj.script.Script)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1 Random (java.util.Random)1 ECKey (org.ethereum.crypto.ECKey)1 Test (org.junit.Test)1