Search in sources :

Example 6 with RepositoryLocator

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);
    }
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) BlockStore(org.ethereum.db.BlockStore)

Example 7 with RepositoryLocator

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;
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BlockExecutor(co.rsk.core.bc.BlockExecutor) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 8 with RepositoryLocator

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;
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 9 with RepositoryLocator

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());
    }
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) RskTestFactory(org.ethereum.util.RskTestFactory) TestGenesisLoader(co.rsk.core.genesis.TestGenesisLoader) Test(org.junit.Test)

Example 10 with RepositoryLocator

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());
    }
}
Also used : BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) TransactionGateway(co.rsk.net.TransactionGateway) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) RepositoryLocator(co.rsk.db.RepositoryLocator) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ReceiptStore(org.ethereum.db.ReceiptStore) Test(org.junit.Test)

Aggregations

RepositoryLocator (co.rsk.db.RepositoryLocator)38 Test (org.junit.Test)25 BlockStore (org.ethereum.db.BlockStore)21 RepositorySnapshot (co.rsk.db.RepositorySnapshot)18 BlockExecutor (co.rsk.core.bc.BlockExecutor)15 ActivationConfigsForTest (org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)14 HashMapDB (org.ethereum.datasource.HashMapDB)10 TestSystemProperties (co.rsk.config.TestSystemProperties)9 Coin (co.rsk.core.Coin)7 World (co.rsk.test.World)7 RskAddress (co.rsk.core.RskAddress)6 StateRootHandler (co.rsk.db.StateRootHandler)6 TransactionGateway (co.rsk.net.TransactionGateway)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)6 TrieStore (co.rsk.trie.TrieStore)6 SimpleChannelManager (org.ethereum.rpc.Simples.SimpleChannelManager)6 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)6 RskSystemProperties (co.rsk.config.RskSystemProperties)5 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5