Search in sources :

Example 6 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class TransactionModuleTest method internalCreateEnvironment.

private Web3Impl internalCreateEnvironment(Blockchain blockchain, MiningMainchainView mainchainView, ReceiptStore receiptStore, TransactionPool transactionPool, BlockStore blockStore, boolean mineInstant, StateRootHandler stateRootHandler, RepositoryLocator repositoryLocator, TransactionGateway transactionGateway, TransactionExecutorFactory transactionExecutorFactory) {
    transactionPool.processBest(blockchain.getBestBlock());
    ConfigCapabilities configCapabilities = new SimpleConfigCapabilities();
    CompositeEthereumListener compositeEthereumListener = new CompositeEthereumListener();
    Ethereum eth = new EthereumImpl(new ChannelManagerImpl(config, new SyncPool(compositeEthereumListener, blockchain, config, null, null, null)), transactionGateway, compositeEthereumListener, blockchain);
    MinerClock minerClock = new MinerClock(true, Clock.systemUTC());
    this.transactionExecutorFactory = transactionExecutorFactory;
    MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, // stateRootHandler,
    this.transactionExecutorFactory);
    MinerServer minerServer = new MinerServerImpl(config, eth, mainchainView, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(config.getActivationConfig(), miningConfig, repositoryLocator, blockStore, transactionPool, new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants()), new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), mock(BlockUnclesValidationRule.class), minerClock, blockFactory, blockExecutor, new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils()), minerClock, blockFactory, new BuildInfo("cb7f28e", "master"), miningConfig);
    Wallet wallet = WalletFactory.createWallet();
    PersonalModuleWalletEnabled personalModule = new PersonalModuleWalletEnabled(config, eth, wallet, transactionPool);
    MinerClient minerClient = new MinerClientImpl(null, minerServer, config.minerClientDelayBetweenBlocks(), config.minerClientDelayBetweenRefreshes());
    EthModuleTransaction transactionModule;
    ReversibleTransactionExecutor reversibleTransactionExecutor1 = new ReversibleTransactionExecutor(repositoryLocator, this.transactionExecutorFactory);
    if (mineInstant) {
        transactionModule = new EthModuleTransactionInstant(config.getNetworkConstants(), wallet, transactionPool, minerServer, minerClient, blockchain, transactionGateway, blockExecutor);
    } else {
        transactionModule = new EthModuleTransactionBase(config.getNetworkConstants(), wallet, transactionPool, transactionGateway);
    }
    final RepositoryBtcBlockStoreWithCache.Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    EthModule ethModule = new EthModule(config.getNetworkConstants().getBridgeConstants(), config.getNetworkConstants().getChainId(), blockchain, transactionPool, reversibleTransactionExecutor1, new ExecutionBlockRetriever(mainchainView, blockchain, null, null), repositoryLocator, new EthModuleWalletEnabled(wallet), transactionModule, new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig()), config.getGasEstimationCap());
    TxPoolModule txPoolModule = new TxPoolModuleImpl(transactionPool);
    DebugModule debugModule = new DebugModuleImpl(null, null, Web3Mocks.getMockMessageHandler(), null);
    ChannelManager channelManager = new SimpleChannelManager();
    return new Web3RskImpl(eth, blockchain, config, minerClient, Web3Mocks.getMockMinerServer(), personalModule, ethModule, null, txPoolModule, null, debugModule, null, null, channelManager, null, null, blockStore, receiptStore, null, null, null, configCapabilities, null, null, null, null);
}
Also used : ConfigCapabilities(org.ethereum.net.client.ConfigCapabilities) SimpleConfigCapabilities(org.ethereum.rpc.Simples.SimpleConfigCapabilities) Web3RskImpl(co.rsk.rpc.Web3RskImpl) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) PersonalModuleWalletEnabled(co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) SyncPool(org.ethereum.sync.SyncPool) Ethereum(org.ethereum.facade.Ethereum) DebugModule(co.rsk.rpc.modules.debug.DebugModule) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) ChannelManagerImpl(org.ethereum.net.server.ChannelManagerImpl) SimpleChannelManager(org.ethereum.rpc.Simples.SimpleChannelManager) ChannelManager(org.ethereum.net.server.ChannelManager) EthereumImpl(org.ethereum.facade.EthereumImpl) TxPoolModuleImpl(co.rsk.rpc.modules.txpool.TxPoolModuleImpl) DebugModuleImpl(co.rsk.rpc.modules.debug.DebugModuleImpl) MiningConfig(co.rsk.config.MiningConfig) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) BuildInfo(org.ethereum.util.BuildInfo) SimpleConfigCapabilities(org.ethereum.rpc.Simples.SimpleConfigCapabilities) TxPoolModule(co.rsk.rpc.modules.txpool.TxPoolModule)

Example 7 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class BlocksBloomServiceTest method processFirstRangeUsingEmitter.

@Test
public void processFirstRangeUsingEmitter() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 8, false, false);
    CompositeEthereumListener emitter = new CompositeEthereumListener();
    KeyValueDataSource dataSource = new HashMapDB();
    BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
    BlocksBloomService blocksBloomService = new BlocksBloomService(emitter, blocksBloomStore, world.getBlockStore());
    blocksBloomService.start();
    emitter.onBlock(blockchain.getBlockByNumber(4), null);
    emitter.onBlock(blockchain.getBlockByNumber(6), null);
    blocksBloomService.stop();
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(1, dataSource.keys().size());
    Assert.assertNotNull(dataSource.get(longToKey(0)));
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 8 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class BlocksBloomServiceTest method processOnlySecondRangeUsingEmitter.

@Test
public void processOnlySecondRangeUsingEmitter() {
    World world = new World();
    Blockchain blockchain = world.getBlockChain();
    BlockChainBuilder.extend(blockchain, 10, false, false);
    CompositeEthereumListener emitter = new CompositeEthereumListener();
    KeyValueDataSource dataSource = new HashMapDB();
    BlocksBloomStore blocksBloomStore = new BlocksBloomStore(4, 2, dataSource);
    BlocksBloomService blocksBloomService = new BlocksBloomService(emitter, blocksBloomStore, world.getBlockStore());
    blocksBloomService.start();
    emitter.onBlock(blockchain.getBlockByNumber(9), null);
    blocksBloomService.stop();
    Assert.assertFalse(dataSource.keys().isEmpty());
    Assert.assertEquals(1, dataSource.keys().size());
    Assert.assertNull(dataSource.get(longToKey(0)));
    Assert.assertNotNull(dataSource.get(longToKey(4)));
}
Also used : CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) Blockchain(org.ethereum.core.Blockchain) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) World(co.rsk.test.World) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 9 with CompositeEthereumListener

use of org.ethereum.listener.CompositeEthereumListener in project rskj by rsksmart.

the class ImportLightTest method createBlockchain.

public static BlockChainImpl createBlockchain(Genesis genesis, TestSystemProperties config, Repository repository, BlockStore blockStore, TrieStore trieStore) {
    BlockFactory blockFactory = new BlockFactory(config.getActivationConfig());
    CompositeEthereumListener listener = new TestCompositeEthereumListener();
    KeyValueDataSource ds = new HashMapDB();
    ds.init();
    ReceiptStore receiptStore = new ReceiptStoreImpl(ds);
    ReceivedTxSignatureCache receivedTxSignatureCache = new ReceivedTxSignatureCache();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(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, receivedTxSignatureCache, 10, 100);
    BlockChainImpl blockchain = new BlockChainImpl(blockStore, receiptStore, transactionPool, listener, new DummyBlockValidator(), new BlockExecutor(config.getActivationConfig(), repositoryLocator, transactionExecutorFactory), stateRootHandler);
    blockchain.setNoValidation(true);
    Repository track = repository.startTracking();
    for (Map.Entry<RskAddress, AccountState> accountsEntry : genesis.getAccounts().entrySet()) {
        RskAddress accountAddress = accountsEntry.getKey();
        track.createAccount(accountAddress);
        track.addBalance(accountAddress, accountsEntry.getValue().getBalance());
    }
    track.commit();
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    blockchain.setStatus(genesis, genesis.getCumulativeDifficulty());
    return blockchain;
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) DummyBlockValidator(co.rsk.validators.DummyBlockValidator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) CompositeEthereumListener(org.ethereum.listener.CompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) TestCompositeEthereumListener(org.ethereum.listener.TestCompositeEthereumListener) RskAddress(co.rsk.core.RskAddress) KeyValueDataSource(org.ethereum.datasource.KeyValueDataSource) Map(java.util.Map) ReceiptStore(org.ethereum.db.ReceiptStore)

Aggregations

CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)9 HashMapDB (org.ethereum.datasource.HashMapDB)6 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)6 World (co.rsk.test.World)4 Blockchain (org.ethereum.core.Blockchain)4 Test (org.junit.Test)4 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BlockExecutor (co.rsk.core.bc.BlockExecutor)2 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)2 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)2 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)2 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)2 Before (org.junit.Before)2 MiningConfig (co.rsk.config.MiningConfig)1 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RskAddress (co.rsk.core.RskAddress)1 TestGenesisLoader (co.rsk.core.genesis.TestGenesisLoader)1 RepositoryLocator (co.rsk.db.RepositoryLocator)1 StateRootHandler (co.rsk.db.StateRootHandler)1