Search in sources :

Example 1 with Sha256Hash

use of co.rsk.bitcoinj.core.Sha256Hash in project rskj by rsksmart.

the class PegTestUtils method createHash.

public static Sha256Hash createHash() {
    byte[] bytes = new byte[32];
    bytes[0] = (byte) nhash++;
    Sha256Hash hash = Sha256Hash.wrap(bytes);
    return hash;
}
Also used : Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash)

Example 2 with Sha256Hash

use of co.rsk.bitcoinj.core.Sha256Hash in project rskj by rsksmart.

the class ReceiveHeadersTest method doReceiveHeaders.

private ExecutionStats doReceiveHeaders(String caseName, int times, int numHeaders, int forkDepth) throws VMException {
    String name = String.format("%s-forkdepth-%d-headers-%d", caseName, forkDepth, numHeaders);
    ExecutionStats stats = new ExecutionStats(name);
    int totalHeaders = numHeaders + forkDepth;
    return executeAndAverage(name, times, generateABIEncoder(totalHeaders, totalHeaders, forkDepth), buildInitializer(1000, 2000), Helper.getZeroValueTxBuilder(Helper.getRandomFederatorECKey()), Helper.getRandomHeightProvider(10), stats, (EnvironmentBuilder.Environment environment, byte[] result) -> {
        BridgeStorageProvider bridgeStorageProvider = new BridgeStorageProvider((Repository) environment.getBenchmarkedRepository(), PrecompiledContracts.BRIDGE_ADDR, constants.getBridgeConstants(), activationConfig.forBlock(0));
        btcBlockStore = new RepositoryBtcBlockStoreWithCache(BridgeRegTestConstants.getInstance().getBtcParams(), (Repository) environment.getBenchmarkedRepository(), new HashMap<>(), PrecompiledContracts.BRIDGE_ADDR, bridgeConstants, bridgeStorageProvider, activationConfig.forBlock(0));
        Sha256Hash bestBlockHash = null;
        try {
            bestBlockHash = btcBlockStore.getChainHead().getHeader().getHash();
        } catch (BlockStoreException e) {
            Assert.fail(e.getMessage());
        }
        Assert.assertEquals(expectedBestBlock.getHash(), bestBlockHash);
    });
}
Also used : RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) Repository(org.ethereum.core.Repository) BlockStoreException(co.rsk.bitcoinj.store.BlockStoreException) HashMap(java.util.HashMap) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash)

Example 3 with Sha256Hash

use of co.rsk.bitcoinj.core.Sha256Hash 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, BtcBlockStore blockStore) -> {
        int hashesToGenerate = Helper.randomInRange(minHashes, maxHashes);
        int randomHashIndex = Helper.randomInRange(0, hashesToGenerate - 1);
        Random rnd = new Random();
        for (int i = 0; i < hashesToGenerate; i++) {
            Sha256Hash hash = Sha256Hash.of(BigInteger.valueOf(rnd.nextLong()).toByteArray());
            long height = Helper.randomInRange(minHeight, maxHeight);
            try {
                provider.setHeightBtcTxhashAlreadyProcessed(hash, height);
            } catch (IOException e) {
                throw new RuntimeException("Exception trying to gather hashes already processed for benchmarking");
            }
            if (i == randomHashIndex) {
                randomHashInMap = hash;
            }
        }
    };
}
Also used : Repository(org.ethereum.core.Repository) Random(java.util.Random) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) BtcBlockStore(co.rsk.bitcoinj.store.BtcBlockStore) IOException(java.io.IOException)

Example 4 with Sha256Hash

use of co.rsk.bitcoinj.core.Sha256Hash in project rskj by rsksmart.

the class LockTest method getBtcTxHashProcessedHeight_notProcessed.

private void getBtcTxHashProcessedHeight_notProcessed(int times, ExecutionStats stats) throws VMException {
    Sha256Hash hash = Sha256Hash.of(BigInteger.valueOf(new Random().nextLong()).toByteArray());
    ABIEncoder abiEncoder = (int executionIndex) -> Bridge.GET_BTC_TX_HASH_PROCESSED_HEIGHT.encode(new Object[] { ByteUtil.toHexString(hash.getBytes()) });
    executeAndAverage("getBtcTxHashProcessedHeight-notProcessed", times, abiEncoder, buildInitializer(), Helper.getZeroValueRandomSenderTxBuilder(), Helper.getRandomHeightProvider(10), stats);
}
Also used : Random(java.util.Random) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash)

Example 5 with Sha256Hash

use of co.rsk.bitcoinj.core.Sha256Hash in project rskj by rsksmart.

the class RepositoryBtcBlockStoreWithCache method getInMainchain.

@Override
public Optional<StoredBlock> getInMainchain(int height) {
    Optional<Sha256Hash> bestBlockHash = bridgeStorageProvider.getBtcBestBlockHashByHeight(height);
    if (!bestBlockHash.isPresent()) {
        logger.trace("[getInMainchain] Block at height {} not present in storage", height);
        return Optional.empty();
    }
    StoredBlock block = get(bestBlockHash.get());
    if (block == null) {
        logger.trace("[getInMainchain] Block with hash {} not found in storage", bestBlockHash.get());
        return Optional.empty();
    }
    logger.trace("[getInMainchain] Found block with hash {} at height {}", bestBlockHash.get(), height);
    return Optional.of(block);
}
Also used : StoredBlock(co.rsk.bitcoinj.core.StoredBlock) Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash)

Aggregations

Sha256Hash (co.rsk.bitcoinj.core.Sha256Hash)40 Test (org.junit.Test)17 StoredBlock (co.rsk.bitcoinj.core.StoredBlock)15 BtcTransaction (co.rsk.bitcoinj.core.BtcTransaction)11 BtcBlock (co.rsk.bitcoinj.core.BtcBlock)9 Script (co.rsk.bitcoinj.script.Script)7 BlockStoreException (co.rsk.bitcoinj.store.BlockStoreException)7 Repository (org.ethereum.core.Repository)7 BtcECKey (co.rsk.bitcoinj.core.BtcECKey)6 TransactionOutPoint (co.rsk.bitcoinj.core.TransactionOutPoint)6 ArrayList (java.util.ArrayList)6 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)6 IOException (java.io.IOException)5 PartialMerkleTree (co.rsk.bitcoinj.core.PartialMerkleTree)4 TransactionInput (co.rsk.bitcoinj.core.TransactionInput)4 TransactionSignature (co.rsk.bitcoinj.crypto.TransactionSignature)4 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)4 BigInteger (java.math.BigInteger)4 MutableRepository (org.ethereum.db.MutableRepository)4 VerificationException (co.rsk.bitcoinj.core.VerificationException)3