Search in sources :

Example 1 with AdminInfo

use of org.ethereum.manager.AdminInfo 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 AdminInfo

use of org.ethereum.manager.AdminInfo in project rskj by rsksmart.

the class BlockChainImplTest method createBlockChain.

private static BlockChainImpl createBlockChain(Repository repository, IndexedBlockStore blockStore, BlockValidatorImpl blockValidator) {
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    AdminInfo adminInfo = new SimpleAdminInfo();
    EthereumListener listener = new BlockExecutorTest.SimpleEthereumListener();
    BlockChainImpl blockChain = new BlockChainImpl(config, repository, blockStore, receiptStore, null, listener, adminInfo, blockValidator);
    TransactionPoolImpl transactionPool = new TransactionPoolImpl(config, repository, blockStore, receiptStore, null, listener, 10, 100);
    blockChain.setTransactionPool(transactionPool);
    return blockChain;
}
Also used : ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) EthereumListener(org.ethereum.listener.EthereumListener) AdminInfo(org.ethereum.manager.AdminInfo) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) HashMapDB(org.ethereum.datasource.HashMapDB) ReceiptStore(org.ethereum.db.ReceiptStore)

Example 3 with AdminInfo

use of org.ethereum.manager.AdminInfo 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

HashMapDB (org.ethereum.datasource.HashMapDB)3 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)3 AdminInfo (org.ethereum.manager.AdminInfo)3 RskAddress (co.rsk.core.RskAddress)2 RepositoryImpl (co.rsk.db.RepositoryImpl)2 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)2 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)2 ReceiptStore (org.ethereum.db.ReceiptStore)2 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)2 EthereumListener (org.ethereum.listener.EthereumListener)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 BlockDifficulty (co.rsk.core.BlockDifficulty)1 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 RepositoryBlockStore (co.rsk.peg.RepositoryBlockStore)1 BlockValidator (co.rsk.validators.BlockValidator)1 HashMap (java.util.HashMap)1 GenesisConfig (org.ethereum.config.blockchain.GenesisConfig)1 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)1 EthereumListenerAdapter (org.ethereum.listener.EthereumListenerAdapter)1