Search in sources :

Example 1 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis) {
    RskSystemProperties config = new RskSystemProperties();
    config.setBlockchainConfig(new GenesisConfig(new GenesisConfig.GenesisConstants() {

        @Override
        public BlockDifficulty getMinimumDifficulty() {
            return new BlockDifficulty(BigInteger.ONE);
        }
    }));
    IndexedBlockStore blockStore = new IndexedBlockStore(new HashMap<>(), new HashMapDB(), null);
    Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
    EthereumListenerAdapter listener = new EthereumListenerAdapter();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockChainImpl blockchain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, new AdminInfo(), new DummyBlockValidator());
    blockchain.setNoValidation(true);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, null, receiptStore, null, listener, 10, 100);
    blockchain.setTransactionPool(transactionPool);
    Repository track = repository.startTracking();
    for (RskAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getAccountState().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setBestBlock(genesis);
    blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) AdminInfo(org.ethereum.manager.AdminInfo) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockDifficulty(co.rsk.core.BlockDifficulty) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) RepositoryImpl(co.rsk.db.RepositoryImpl) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) RskSystemProperties(co.rsk.config.RskSystemProperties) ReceiptStore(org.ethereum.db.ReceiptStore) GenesisConfig(org.ethereum.config.blockchain.GenesisConfig)

Example 2 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.

the class BlockChainBuilder method build.

public BlockChainImpl build() {
    BlocksIndex blocksIndex = new HashMapBlocksIndex();
    if (config == null) {
        config = new TestSystemProperties();
    }
    if (trieStore == null) {
        trieStore = new TrieStoreImpl(new HashMapDB().setClearOnClose(false));
    }
    if (repository == null) {
        repository = new MutableRepository(trieStore, new Trie(trieStore));
    }
    if (stateRootHandler == null) {
        stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    }
    if (genesis == null) {
        genesis = new BlockGenerator().getGenesisBlock();
    }
    GenesisLoaderImpl.loadGenesisInitalState(repository, genesis);
    repository.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    if (blockStore == null) {
        blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), blocksIndex);
    }
    if (receiptStore == null) {
        KeyValueDataSource ds = new HashMapDB();
        ds.init();
        receiptStore = new ReceiptStoreImpl(ds);
    }
    if (listener == null) {
        listener = new BlockExecutorTest.SimpleEthereumListener();
    }
    if (bridgeSupportFactory == null) {
        bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    }
    BlockValidatorBuilder validatorBuilder = new BlockValidatorBuilder();
    validatorBuilder.addBlockRootValidationRule().addBlockUnclesValidationRule(blockStore).addBlockTxsValidationRule(trieStore).blockStore(blockStore);
    BlockValidator blockValidator = validatorBuilder.build();
    ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(receivedTxSignatureCache);
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
    repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    transactionPool = new TransactionPoolImpl(config, repositoryLocator, this.blockStore, blockFactory, new TestCompositeEthereumListener(), transactionExecutorFactory, new ReceivedTxSignatureCache(), 10, 100);
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory);
    BlockChainImpl blockChain = new BlockChainLoader(blockStore, receiptStore, transactionPool, listener, blockValidator, blockExecutor, genesis, stateRootHandler, repositoryLocator).loadBlockchain();
    if (this.testing) {
        blockChain.setBlockValidator(new DummyBlockValidator());
        blockChain.setNoValidation(true);
    }
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    if (this.blocks != null) {
        for (Block b : this.blocks) {
            blockExecutor.executeAndFillAll(b, blockChain.getBestBlock().getHeader());
            blockChain.tryToConnect(b);
        }
    }
    return blockChain;
}
Also used : BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) BlockValidator(co.rsk.validators.BlockValidator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) Trie(co.rsk.trie.Trie) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) BlockChainLoader(org.ethereum.core.genesis.BlockChainLoader) HashMapDB(org.ethereum.datasource.HashMapDB) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 3 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.

the class TestRunner method runTestCase.

public List<String> runTestCase(BlockTestCase testCase) {
    /* 1 */
    // Create genesis + init pre state
    ValidationStats vStats = new ValidationStats();
    Block genesis = build(testCase.getGenesisBlockHeader(), null, null);
    TrieStore trieStore = new TrieStoreImpl(new HashMapDB());
    Repository repository = RepositoryBuilder.build(trieStore, testCase.getPre());
    IndexedBlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    CompositeEthereumListener listener = new TestCompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, blockStore, receiptStore, blockFactory, new ProgramInvokeFactoryImpl(), null, blockTxSignatureCache);
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    RepositoryLocator repositoryLocator = new RepositoryLocator(trieStore, stateRootHandler);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repositoryLocator, null, blockFactory, listener, transactionExecutorFactory, new ReceivedTxSignatureCache(), 10, 100);
    BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, null, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), transactionExecutorFactory), stateRootHandler);
    blockchain.setNoValidation(true);
    blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
    /* 2 */
    // Create block traffic list
    List<Block> blockTraffic = new ArrayList<>();
    for (BlockTck blockTck : testCase.getBlocks()) {
        Block block = build(blockTck.getBlockHeader(), blockTck.getTransactions(), blockTck.getUncleHeaders());
        Block tBlock = null;
        try {
            byte[] rlp = parseData(blockTck.getRlp());
            tBlock = blockFactory.decodeBlock(rlp);
            ArrayList<String> outputSummary = BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader(), null);
            if (!outputSummary.isEmpty()) {
                for (String output : outputSummary) logger.error("at block {}: {}", Integer.toString(blockTraffic.size()), output);
            }
            blockTraffic.add(tBlock);
        } catch (Exception e) {
            System.out.println("*** Exception");
        }
    }
    // Inject blocks to the blockchain execution
    for (Block block : blockTraffic) {
        ImportResult importResult = blockchain.tryToConnect(block);
        logger.debug("{} ~ {} difficulty: {} ::: {}", block.getPrintableHash(), toPrintableHash(block.getParentHash().getBytes()), block.getCumulativeDifficulty(), importResult.toString());
    }
    // Check state root matches last valid block
    List<String> results = new ArrayList<>();
    String currRoot = ByteUtil.toHexString(repository.getRoot());
    byte[] bestHash = Hex.decode(testCase.getLastblockhash());
    String finalRoot = ByteUtil.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot());
    if (validateStateRoots) {
        if (!finalRoot.equals(currRoot)) {
            String formattedString = String.format("Root hash doesn't match best: expected: %s current: %s", finalRoot, currRoot);
            results.add(formattedString);
        }
    }
    Repository postRepository = RepositoryBuilder.build(testCase.getPostState());
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, validateStateRoots, validateBalances, null);
    results.addAll(repoResults);
    return results;
}
Also used : BlockChainImpl(co.rsk.core.bc.BlockChainImpl) TrieStore(co.rsk.trie.TrieStore) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockTck(org.ethereum.jsontestsuite.model.BlockTck) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) TrieStoreImpl(co.rsk.trie.TrieStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) HashMapDB(org.ethereum.datasource.HashMapDB) IOException(java.io.IOException) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 4 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.

the class BlockChainImplTest method createWithoutArgumentsAndUnusedMethods.

@Test
public void createWithoutArgumentsAndUnusedMethods() {
    BlockChainImpl blockChain = new BlockChainImpl(config, null, null, null, null, null, null, new DummyBlockValidator());
    blockChain.setExitOn(0);
    blockChain.close();
}
Also used : DummyBlockValidator(co.rsk.validators.DummyBlockValidator) Test(org.junit.Test)

Example 5 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator in project rskj by rsksmart.

the class RskTestFactory method getBlockchain.

public BlockChainImpl getBlockchain() {
    if (blockchain == null) {
        blockchain = new BlockChainImpl(config, getRepository(), getBlockStore(), getReceiptStore(), // circular dependency
        null, null, null, new DummyBlockValidator());
        TransactionPool transactionPool = getTransactionPool();
        blockchain.setTransactionPool(transactionPool);
    }
    return blockchain;
}
Also used : DummyBlockValidator(co.rsk.validators.DummyBlockValidator) BlockChainImpl(co.rsk.core.bc.BlockChainImpl)

Aggregations

DummyBlockValidator (co.rsk.validators.DummyBlockValidator)7 HashMapDB (org.ethereum.datasource.HashMapDB)5 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)4 RskAddress (co.rsk.core.RskAddress)3 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)3 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)3 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)3 BlockExecutor (co.rsk.core.bc.BlockExecutor)2 RepositoryImpl (co.rsk.db.RepositoryImpl)2 BlockValidator (co.rsk.validators.BlockValidator)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2 CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)2 AdminInfo (org.ethereum.manager.AdminInfo)2 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 TestSystemProperties (co.rsk.config.TestSystemProperties)1