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;
}
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);
});
}
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;
}
}
};
}
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);
}
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);
}
Aggregations