Search in sources :

Example 6 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)

Example 7 with DummyBlockValidator

use of co.rsk.validators.DummyBlockValidator 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;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) HashMap(java.util.HashMap) AdminInfo(org.ethereum.manager.AdminInfo) HashMapDB(org.ethereum.datasource.HashMapDB) BlockValidator(co.rsk.validators.BlockValidator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) RepositoryImpl(co.rsk.db.RepositoryImpl) RepositoryBlockStore(co.rsk.peg.RepositoryBlockStore) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource)

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