use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class RewindBlocks method onExecute.
@Override
protected void onExecute(@Nonnull String[] args, @Nonnull RskContext ctx) {
BlockStore blockStore = ctx.getBlockStore();
String blockNumOrOp = args[0];
if ("fmi".equals(blockNumOrOp)) {
RepositoryLocator repositoryLocator = ctx.getRepositoryLocator();
printMinInconsistentBlock(blockStore, repositoryLocator);
} else if ("rbc".equals(blockNumOrOp)) {
RepositoryLocator repositoryLocator = ctx.getRepositoryLocator();
rewindInconsistentBlocks(blockStore, repositoryLocator);
} else {
long blockNumber = Long.parseLong(blockNumOrOp);
rewindBlocks(blockNumber, blockStore);
}
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class World method getBlockExecutor.
public BlockExecutor getBlockExecutor() {
final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
if (this.blockExecutor == null) {
this.blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache));
}
return this.blockExecutor;
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class BlockBuilder method build.
public Block build() {
Block block = blockGenerator.createChildBlock(parent, txs, uncles, difficulty, this.minGasPrice, gasLimit);
if (blockChain != null) {
final TestSystemProperties config = new TestSystemProperties();
StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
executor.executeAndFill(block, parent.getHeader());
}
return block;
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class BlockchainLoaderTest method testLoadBlockchainWithInconsistentBlock.
@Test
public void testLoadBlockchainWithInconsistentBlock() {
RskTestFactory objects = new RskTestFactory() {
@Override
protected synchronized RepositoryLocator buildRepositoryLocator() {
RepositoryLocator repositoryLocatorSpy = spy(super.buildRepositoryLocator());
doReturn(Optional.empty()).when(repositoryLocatorSpy).findSnapshotAt(any());
return repositoryLocatorSpy;
}
@Override
protected GenesisLoader buildGenesisLoader() {
return new TestGenesisLoader(getTrieStore(), "blockchain_loader_genesis.json", BigInteger.ZERO, true, true, true);
}
};
try {
// calls loadBlockchain
objects.getBlockchain();
fail();
} catch (RuntimeException e) {
String errorMessage = String.format("Best block is not consistent with the state db. Consider using `%s` cli tool to rewind inconsistent blocks", RewindBlocks.class.getSimpleName());
assertEquals(errorMessage, e.getMessage());
}
}
use of co.rsk.db.RepositoryLocator in project rskj by rsksmart.
the class TransactionModuleTest method sendSeveralTransactionsWithAutoMining.
/**
* This test send a several transactions, and should be mine 1 transaction in each block.
*/
@Test
public void sendSeveralTransactionsWithAutoMining() {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
BlockChainImpl blockchain = world.getBlockChain();
MiningMainchainView mainchainView = new MiningMainchainViewImpl(world.getBlockStore(), 1);
RepositoryLocator repositoryLocator = world.getRepositoryLocator();
BlockStore blockStore = world.getBlockStore();
TransactionPool transactionPool = world.getTransactionPool();
TransactionGateway transactionGateway = new TransactionGateway(new SimpleChannelManager(), transactionPool);
Web3Impl web3 = createEnvironment(blockchain, mainchainView, receiptStore, transactionPool, blockStore, true, createStateRootHandler(), repositoryLocator, world.getBlockTxSignatureCache(), transactionGateway);
for (int i = 1; i < 100; i++) {
String tx = sendTransaction(web3, repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader()));
// The goal of this test is transaction testing and not block mining testing
// Hence, there is no setup for listeners and best blocks must be added manually
// to mainchain view object that is used by miner server to build new blocks.
mainchainView.addBest(blockchain.getBestBlock().getHeader());
Transaction txInBlock = getTransactionFromBlockWhichWasSend(blockchain, tx);
Assert.assertEquals(i, blockchain.getBestBlock().getNumber());
Assert.assertEquals(2, blockchain.getBestBlock().getTransactionsList().size());
Assert.assertEquals(tx, txInBlock.getHash().toJsonString());
}
}
Aggregations