Search in sources :

Example 1 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl in project rskj by rsksmart.

the class Web3ImplLogsTest method getWeb3WithContractInvoke.

private Web3Impl getWeb3WithContractInvoke() {
    ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
    World world = new World(receiptStore);
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
    byte[] contractAddress = tx.getContractAddress().getBytes();
    Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
    List<Transaction> tx2s = new ArrayList<>();
    tx2s.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), receiptStore, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool, receiptStore);
    web3.personal_newAccountWithSeed("default");
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) HashMapDB(org.ethereum.datasource.HashMapDB) World(co.rsk.test.World) ReceiptStoreImpl(org.ethereum.db.ReceiptStoreImpl) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) ReceiptStore(org.ethereum.db.ReceiptStore) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 2 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl in project rskj by rsksmart.

the class Web3ImplLogsTest method getWeb3WithContractCall.

private Web3Impl getWeb3WithContractCall(World world) {
    Account acc1 = new AccountBuilder(world).name("notDefault").balance(Coin.valueOf(10000000)).build();
    // acc1 Account created address should be 661b05ca9eb621164906671efd2731ce0d7dd8b4
    Block genesis = world.getBlockByName("g00");
    Transaction tx;
    tx = getContractTransaction(acc1);
    List<Transaction> txs = new ArrayList<>();
    txs.add(tx);
    BlockChainImpl blockChain = world.getBlockChain();
    Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block1));
    byte[] contractAddress = tx.getContractAddress().getBytes();
    // Now create a transaction that invokes Increment()
    Transaction tx2 = getContractTransactionWithInvoke(acc1, contractAddress);
    List<Transaction> tx2s = new ArrayList<>();
    tx2s.add(tx2);
    Block block2 = new BlockBuilder(world).parent(block1).transactions(tx2s).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block2));
    Transaction tx3 = getContractTransactionWithCall(acc1, contractAddress);
    List<Transaction> tx3s = new ArrayList<>();
    tx3s.add(tx3);
    Block block3 = new BlockBuilder(world).parent(block2).transactions(tx3s).build();
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(block3));
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepository(), blockChain.getBlockStore(), null, null, null, 10, 100);
    Web3Impl web3 = createWeb3(world.getBlockChain(), transactionPool);
    web3.personal_newAccountWithSeed("default");
    web3.personal_newAccountWithSeed("notDefault");
    return web3;
}
Also used : TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) ArrayList(java.util.ArrayList) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) AccountBuilder(co.rsk.test.builders.AccountBuilder) BlockBuilder(co.rsk.test.builders.BlockBuilder)

Example 3 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl 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 4 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl 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 5 with TransactionPoolImpl

use of co.rsk.core.bc.TransactionPoolImpl in project rskj by rsksmart.

the class Web3ImplTest method createWeb3.

private Web3Impl createWeb3(World world, BlockProcessor blockProcessor, ReceiptStore receiptStore) {
    BlockChainImpl blockChain = world.getBlockChain();
    BlockStore blockStore = world.getBlockStore();
    TransactionExecutorFactory transactionExecutorFactory = buildTransactionExecutorFactory(blockStore, world.getBlockTxSignatureCache());
    TransactionPool transactionPool = new TransactionPoolImpl(config, world.getRepositoryLocator(), blockStore, blockFactory, null, transactionExecutorFactory, world.getReceivedTxSignatureCache(), 10, 100);
    RepositoryLocator repositoryLocator = new RepositoryLocator(world.getTrieStore(), world.getStateRootHandler());
    return createWeb3(Web3Mocks.getMockEthereum(), blockChain, repositoryLocator, transactionPool, blockStore, blockProcessor, new SimpleConfigCapabilities(), receiptStore);
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) TransactionPoolImpl(co.rsk.core.bc.TransactionPoolImpl) BlockStore(org.ethereum.db.BlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl)

Aggregations

TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)12 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)9 HashMapDB (org.ethereum.datasource.HashMapDB)7 ReceiptStore (org.ethereum.db.ReceiptStore)6 ReceiptStoreImpl (org.ethereum.db.ReceiptStoreImpl)6 World (co.rsk.test.World)5 BlockStore (org.ethereum.db.BlockStore)5 AccountBuilder (co.rsk.test.builders.AccountBuilder)4 BlockBuilder (co.rsk.test.builders.BlockBuilder)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 ArrayList (java.util.ArrayList)3 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)3 RskAddress (co.rsk.core.RskAddress)2 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)2 BlockExecutor (co.rsk.core.bc.BlockExecutor)2 RepositoryLocator (co.rsk.db.RepositoryLocator)2 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)2 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)2 CompositeEthereumListener (org.ethereum.listener.CompositeEthereumListener)2 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)2