Search in sources :

Example 6 with BtcBlock

use of co.rsk.bitcoinj.core.BtcBlock 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

BtcBlock (co.rsk.bitcoinj.core.BtcBlock)6 Context (co.rsk.bitcoinj.core.Context)4 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)3 NetworkParameters (co.rsk.bitcoinj.core.NetworkParameters)3 Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)2 RskSystemProperties (co.rsk.config.RskSystemProperties)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Repository (org.ethereum.core.Repository)2 Test (org.junit.Test)2 BtcBlockChain (co.rsk.bitcoinj.core.BtcBlockChain)1 PartialMerkleTree (co.rsk.bitcoinj.core.PartialMerkleTree)1 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)1 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)1 BtcBlockStore (co.rsk.bitcoinj.store.BtcBlockStore)1 RepositoryImplForTesting (co.rsk.db.RepositoryImplForTesting)1 BridgeStorageProvider (co.rsk.peg.BridgeStorageProvider)1 RepositoryBlockStore (co.rsk.peg.RepositoryBlockStore)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1