Search in sources :

Example 1 with BtcBlockChain

use of co.rsk.bitcoinj.core.BtcBlockChain 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);
    };
}
Also used : Context(co.rsk.bitcoinj.core.Context) Repository(org.ethereum.core.Repository) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) RepositoryBlockStore(co.rsk.peg.RepositoryBlockStore) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) BtcBlockChain(co.rsk.bitcoinj.core.BtcBlockChain) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 2 with BtcBlockChain

use of co.rsk.bitcoinj.core.BtcBlockChain 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);
}
Also used : Context(co.rsk.bitcoinj.core.Context) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) BtcBlockChain(co.rsk.bitcoinj.core.BtcBlockChain) Repository(org.ethereum.core.Repository) RepositoryBlockStore(co.rsk.peg.RepositoryBlockStore) BtcBlock(co.rsk.bitcoinj.core.BtcBlock) ArrayList(java.util.ArrayList) List(java.util.List) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Aggregations

BtcBlockChain (co.rsk.bitcoinj.core.BtcBlockChain)2 Context (co.rsk.bitcoinj.core.Context)2 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)2 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)2 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)2 RepositoryBlockStore (co.rsk.peg.RepositoryBlockStore)2 Repository (org.ethereum.core.Repository)2 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1