Search in sources :

Example 11 with BtcBlockStore

use of co.rsk.bitcoinj.store.BtcBlockStore 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

BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)11 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)8 Test (org.junit.Test)8 BridgeConstants (co.rsk.config.BridgeConstants)7 RepositoryImpl (co.rsk.db.RepositoryImpl)7 org.ethereum.core (org.ethereum.core)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 RskAddress (co.rsk.core.RskAddress)6 SimpleBlockChain (co.rsk.peg.simples.SimpleBlockChain)6 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)5 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)4 RskSystemProperties (co.rsk.config.RskSystemProperties)4 Repository (org.ethereum.core.Repository)4 TransactionSignature (co.rsk.bitcoinj.crypto.TransactionSignature)3 Script (co.rsk.bitcoinj.script.Script)3 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)3 RepositoryBlockStore (co.rsk.peg.RepositoryBlockStore)3 BtcBlockChain (co.rsk.bitcoinj.core.BtcBlockChain)2 Context (co.rsk.bitcoinj.core.Context)2 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)1