Search in sources :

Example 1 with TransactionExecutorFactory

use of co.rsk.core.TransactionExecutorFactory in project rskj by rsksmart.

the class RemascTestRunner method start.

public void start() {
    this.blockchain = this.builder.build();
    ((BlockChainImpl) this.blockchain).setNoValidation(true);
    this.addedSiblings = new ArrayList<>();
    List<Block> mainChainBlocks = new ArrayList<>();
    this.blockchain.tryToConnect(this.genesis);
    BlockFactory blockFactory = new BlockFactory(builder.getConfig().getActivationConfig());
    final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(builder.getConfig().getNetworkConstants().getBridgeConstants().getBtcParams()), builder.getConfig().getNetworkConstants().getBridgeConstants(), builder.getConfig().getActivationConfig());
    PrecompiledContracts precompiledContracts = new PrecompiledContracts(builder.getConfig(), bridgeSupportFactory);
    BlockExecutor blockExecutor = new BlockExecutor(builder.getConfig().getActivationConfig(), builder.getRepositoryLocator(), new TransactionExecutorFactory(builder.getConfig(), builder.getBlockStore(), null, blockFactory, programInvokeFactory, precompiledContracts, blockTxSignatureCache));
    for (int i = 0; i <= this.initialHeight; i++) {
        int finalI = i;
        List<SiblingElement> siblingsForCurrentHeight = this.siblingElements.stream().filter(siblingElement -> siblingElement.getHeightToBeIncluded() == finalI).collect(Collectors.toList());
        List<BlockHeader> blockSiblings = new ArrayList<>();
        // Going to add siblings
        BlockDifficulty cummDifficulty = BlockDifficulty.ZERO;
        if (siblingsForCurrentHeight.size() > 0) {
            cummDifficulty = blockchain.getTotalDifficulty();
        }
        for (SiblingElement sibling : siblingsForCurrentHeight) {
            RskAddress siblingCoinbase = TestUtils.randomAddress();
            Block mainchainSiblingParent = mainChainBlocks.get(sibling.getHeight() - 1);
            Block siblingBlock = createBlock(this.genesis, mainchainSiblingParent, PegTestUtils.createHash3(), siblingCoinbase, Collections.emptyList(), minerFee, this.gasPrice, (long) i, this.txValue, this.txSigningKey, null);
            blockSiblings.add(siblingBlock.getHeader());
            builder.getBlockStore().saveBlock(siblingBlock, cummDifficulty.add(siblingBlock.getCumulativeDifficulty()), false);
            this.addedSiblings.add(siblingBlock);
        }
        long txNonce = i;
        RskAddress coinbase = fixedCoinbase != null ? fixedCoinbase : TestUtils.randomAddress();
        Block block = createBlock(this.genesis, this.blockchain.getBestBlock(), PegTestUtils.createHash3(), coinbase, blockSiblings, minerFee, this.gasPrice, txNonce, this.txValue, this.txSigningKey, null);
        mainChainBlocks.add(block);
        blockExecutor.executeAndFillAll(block, this.blockchain.getBestBlock().getHeader());
        block.seal();
        ImportResult result = this.blockchain.tryToConnect(block);
        System.out.println(result);
    }
}
Also used : BlockDifficulty(co.rsk.core.BlockDifficulty) TestUtils(org.ethereum.TestUtils) RskAddress(co.rsk.core.RskAddress) Coin(co.rsk.core.Coin) Keccak256(co.rsk.crypto.Keccak256) ArrayList(java.util.ArrayList) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BigInteger(java.math.BigInteger) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) BlockHashesHelper(co.rsk.core.bc.BlockHashesHelper) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) HashUtil(org.ethereum.crypto.HashUtil) RLP(org.ethereum.util.RLP) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) PegTestUtils(co.rsk.peg.PegTestUtils) Collectors(java.util.stream.Collectors) List(java.util.List) RepositorySnapshot(co.rsk.db.RepositorySnapshot) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) org.ethereum.core(org.ethereum.core) Collections(java.util.Collections) Constants(org.ethereum.config.Constants) ECKey(org.ethereum.crypto.ECKey) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ArrayList(java.util.ArrayList) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) BlockDifficulty(co.rsk.core.BlockDifficulty) RskAddress(co.rsk.core.RskAddress) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts)

Example 2 with TransactionExecutorFactory

use of co.rsk.core.TransactionExecutorFactory 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 3 with TransactionExecutorFactory

use of co.rsk.core.TransactionExecutorFactory in project rskj by rsksmart.

the class StateTestRunner method runImpl.

public List<String> runImpl() {
    vStats = new ValidationStats();
    logger.info("");
    trieStore = new TrieStoreImpl(new HashMapDB());
    repository = RepositoryBuilder.build(trieStore, stateTestCase.getPre());
    logger.info("loaded repository");
    transaction = TransactionBuilder.build(stateTestCase.getTransaction());
    logger.info("transaction: {}", transaction.toString());
    BlockStore blockStore = new IndexedBlockStore(blockFactory, new HashMapDB(), new HashMapBlocksIndex());
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    blockchain = new BlockChainImpl(blockStore, null, null, null, null, new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(trieStore, stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, blockFactory, new ProgramInvokeFactoryImpl(), precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()))), stateRootHandler);
    env = EnvBuilder.build(stateTestCase.getEnv());
    invokeFactory = new TestProgramInvokeFactory(env);
    block = build(env);
    block.setStateRoot(repository.getRoot());
    block.flushRLP();
    blockchain.setStatus(block, block.getCumulativeDifficulty());
    // blockchain.setProgramInvokeFactory(invokeFactory);
    // blockchain.startTracking();
    ProgramResult programResult = executeTransaction(transaction);
    trieStore.flush();
    List<LogInfo> origLogs = programResult.getLogInfoList();
    List<LogInfo> postLogs = LogBuilder.build(stateTestCase.getLogs());
    List<String> logsResult = LogsValidator.valid(origLogs, postLogs, vStats);
    Repository postRepository = RepositoryBuilder.build(stateTestCase.getPost());
    // Balances cannot be validated because has consumption for CALLs differ.
    List<String> repoResults = RepositoryValidator.valid(repository, postRepository, false, false, vStats);
    logger.info("--------- POST Validation---------");
    List<String> outputResults = OutputValidator.valid(ByteUtil.toHexString(programResult.getHReturn()), stateTestCase.getOut(), vStats);
    List<String> results = new ArrayList<>();
    results.addAll(repoResults);
    results.addAll(logsResult);
    results.addAll(outputResults);
    for (String result : results) {
        logger.error(result);
    }
    if ((vStats.storageChecks == 0) && (vStats.logChecks == 0) && (vStats.balancetChecks == 0) && (vStats.outputChecks == 0) && (vStats.blockChecks == 0)) {
        // This generally mean that the test didn't check anything
        // AccountChecks are considered not indicative of the result of the test
        logger.info("IRRELEVANT\n");
    }
    logger.info("\n\n");
    return results;
}
Also used : TrieStoreImpl(co.rsk.trie.TrieStoreImpl) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockStore(org.ethereum.db.BlockStore) LogInfo(org.ethereum.vm.LogInfo) StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) IndexedBlockStore(org.ethereum.db.IndexedBlockStore) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) ProgramResult(org.ethereum.vm.program.ProgramResult) ArrayList(java.util.ArrayList) HashMapDB(org.ethereum.datasource.HashMapDB) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryLocator(co.rsk.db.RepositoryLocator) TestProgramInvokeFactory(org.ethereum.jsontestsuite.TestProgramInvokeFactory) HashMapBlocksIndex(co.rsk.db.HashMapBlocksIndex) ValidationStats(org.ethereum.jsontestsuite.validators.ValidationStats)

Example 4 with TransactionExecutorFactory

use of co.rsk.core.TransactionExecutorFactory in project rskj by rsksmart.

the class BlockExecutorTest method buildBlockExecutor.

private static BlockExecutor buildBlockExecutor(TrieStore store, RskSystemProperties config) {
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    return new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(store, stateRootHandler), new TransactionExecutorFactory(config, null, null, BLOCK_FACTORY, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
}
Also used : PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RskTestFactory(org.ethereum.util.RskTestFactory) HashMapDB(org.ethereum.datasource.HashMapDB) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 5 with TransactionExecutorFactory

use of co.rsk.core.TransactionExecutorFactory in project rskj by rsksmart.

the class World method getBlockExecutor.

public BlockExecutor getBlockExecutor() {
    final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
    Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    if (this.blockExecutor == null) {
        this.blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockStore, null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache));
    }
    return this.blockExecutor;
}
Also used : RepositoryLocator(co.rsk.db.RepositoryLocator) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BlockExecutor(co.rsk.core.bc.BlockExecutor) Factory(co.rsk.peg.BtcBlockStoreWithCache.Factory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Aggregations

TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)18 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)13 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)11 TestSystemProperties (co.rsk.config.TestSystemProperties)8 BlockExecutor (co.rsk.core.bc.BlockExecutor)8 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)8 HashMapDB (org.ethereum.datasource.HashMapDB)7 RskAddress (co.rsk.core.RskAddress)5 RepositoryLocator (co.rsk.db.RepositoryLocator)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 StateRootHandler (co.rsk.db.StateRootHandler)4 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)4 RepositoryBtcBlockStoreWithCache (co.rsk.peg.RepositoryBtcBlockStoreWithCache)4 ReversibleTransactionExecutor (co.rsk.core.ReversibleTransactionExecutor)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)3 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)3 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)3 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)3 Coin (co.rsk.core.Coin)2