use of co.rsk.peg.RepositoryBlockStore in project rskj by rsksmart.
the class LockWhitelistTest method buildInitializer.
private BridgeStorageProviderInitializer buildInitializer() {
final int minSize = 10;
final int maxSize = 100;
final int minBtcBlocks = 500;
final int maxBtcBlocks = 1000;
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);
lockWhitelist = provider.getLockWhitelist();
int size = Helper.randomInRange(minSize, maxSize);
for (int i = 0; i < size; i++) {
Address address = new BtcECKey().toAddress(networkParameters);
Coin value = Helper.randomCoin(Coin.COIN, 1, 30);
lockWhitelist.put(address, value);
}
};
}
use of co.rsk.peg.RepositoryBlockStore 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);
};
}
use of co.rsk.peg.RepositoryBlockStore 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);
}
use of co.rsk.peg.RepositoryBlockStore in project rskj by rsksmart.
the class BlockChainBuilder method build.
public BlockChainImpl build(boolean withoutCleaner) {
if (repository == null)
repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB().setClearOnClose(false)));
if (blockStore == null) {
blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
}
if (receiptStore == null) {
KeyValueDataSource ds = new HashMapDB();
ds.init();
receiptStore = new ReceiptStoreImpl(ds);
}
if (txinfos != null && !txinfos.isEmpty())
for (TransactionInfo txinfo : txinfos) receiptStore.add(txinfo.getBlockHash(), txinfo.getIndex(), txinfo.getReceipt());
EthereumListener listener = new BlockExecutorTest.SimpleEthereumListener();
BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(repository).blockStore(blockStore);
BlockValidator blockValidator = validatorBuilder.build();
if (this.adminInfo == null)
this.adminInfo = new AdminInfo();
BlockChainImpl blockChain = new BlockChainImpl(config, this.repository, this.blockStore, receiptStore, null, listener, this.adminInfo, blockValidator);
if (this.testing) {
blockChain.setBlockValidator(new DummyBlockValidator());
blockChain.setNoValidation(true);
}
TransactionPoolImpl transactionPool;
if (withoutCleaner) {
transactionPool = new TransactionPoolImplNoCleaner(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
} else {
transactionPool = new TransactionPoolImpl(config, blockChain.getRepository(), blockChain.getBlockStore(), receiptStore, new ProgramInvokeFactoryImpl(), new BlockExecutorTest.SimpleEthereumListener(), 10, 100);
}
blockChain.setTransactionPool(transactionPool);
if (this.genesis != null) {
for (RskAddress addr : this.genesis.getPremine().keySet()) {
this.repository.createAccount(addr);
this.repository.addBalance(addr, this.genesis.getPremine().get(addr).getAccountState().getBalance());
}
Repository track = this.repository.startTracking();
new RepositoryBlockStore(config, track, PrecompiledContracts.BRIDGE_ADDR);
track.commit();
this.genesis.setStateRoot(this.repository.getRoot());
this.genesis.flushRLP();
blockChain.setBestBlock(this.genesis);
blockChain.setTotalDifficulty(this.genesis.getCumulativeDifficulty());
}
if (this.blocks != null) {
BlockExecutor blockExecutor = new BlockExecutor(config, repository, receiptStore, blockStore, listener);
for (Block b : this.blocks) {
blockExecutor.executeAndFillAll(b, blockChain.getBestBlock());
blockChain.tryToConnect(b);
}
}
return blockChain;
}
Aggregations