Search in sources :

Example 11 with TransactionExecutorFactory

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

the class NestedContractsTest method buildEthModule.

private EthModule buildEthModule(World world) {
    final TestSystemProperties config = new TestSystemProperties();
    TransactionExecutorFactory executor = new TransactionExecutorFactory(config, world.getBlockStore(), null, null, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, world.getBridgeSupportFactory()), null);
    return new EthModule(null, Constants.REGTEST_CHAIN_ID, world.getBlockChain(), world.getTransactionPool(), new ReversibleTransactionExecutor(world.getRepositoryLocator(), executor), new ExecutionBlockRetriever(null, world.getBlockChain(), null, null), world.getRepositoryLocator(), null, null, world.getBridgeSupportFactory(), config.getGasEstimationCap());
}
Also used : PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) EthModule(co.rsk.rpc.modules.eth.EthModule) ReversibleTransactionExecutor(co.rsk.core.ReversibleTransactionExecutor) ExecutionBlockRetriever(co.rsk.rpc.ExecutionBlockRetriever) TestSystemProperties(co.rsk.config.TestSystemProperties) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 12 with TransactionExecutorFactory

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

the class RskForksBridgeTest method callGetStateForDebuggingTx.

private BridgeState callGetStateForDebuggingTx() throws IOException {
    TestSystemProperties beforeBambooProperties = new TestSystemProperties();
    Transaction rskTx = CallTransaction.createRawTransaction(0, Long.MAX_VALUE, Long.MAX_VALUE, PrecompiledContracts.BRIDGE_ADDR, 0, Bridge.GET_STATE_FOR_DEBUGGING.encode(new Object[] {}), beforeBambooProperties.getNetworkConstants().getChainId());
    rskTx.sign(new byte[] {});
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(beforeBambooProperties, blockStore, null, new BlockFactory(beforeBambooProperties.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(beforeBambooProperties, world.getBridgeSupportFactory()), world.getBlockTxSignatureCache());
    Repository track = repository.startTracking();
    TransactionExecutor executor = transactionExecutorFactory.newInstance(rskTx, 0, blockChain.getBestBlock().getCoinbase(), track, blockChain.getBestBlock(), 0).setLocalCall(true);
    executor.executeTransaction();
    ProgramResult res = executor.getResult();
    Object[] result = Bridge.GET_STATE_FOR_DEBUGGING.decodeResult(res.getHReturn());
    ActivationConfig.ForBlock activations = beforeBambooProperties.getActivationConfig().forBlock(blockChain.getBestBlock().getNumber());
    return BridgeState.create(beforeBambooProperties.getNetworkConstants().getBridgeConstants(), (byte[]) result[0], activations);
}
Also used : ProgramResult(org.ethereum.vm.program.ProgramResult) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) ActivationConfig(org.ethereum.config.blockchain.upgrades.ActivationConfig) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 13 with TransactionExecutorFactory

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

the class StateTestRunner method executeTransaction.

protected ProgramResult executeTransaction(Transaction tx) {
    Repository track = repository.startTracking();
    TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, new BlockStoreDummy(), null, blockFactory, invokeFactory, precompiledContracts, new BlockTxSignatureCache(new ReceivedTxSignatureCache()));
    TransactionExecutor executor = transactionExecutorFactory.newInstance(transaction, 0, new RskAddress(env.getCurrentCoinbase()), track, blockchain.getBestBlock(), 0);
    try {
        executor.executeTransaction();
    } catch (StackOverflowError soe) {
        logger.error(" !!! StackOverflowError: update your java run command with -Xss32M !!!");
        System.exit(-1);
    }
    track.commit();
    return executor.getResult();
}
Also used : BlockStoreDummy(org.ethereum.db.BlockStoreDummy) RskAddress(co.rsk.core.RskAddress) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory)

Example 14 with TransactionExecutorFactory

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

the class TransactionTest method constantCallConflictTest.

@Test
public void constantCallConflictTest() throws Exception {
    /*
          0x095e7baea6a6c7c4c2dfeb977efac326af552d87 contract is the following Solidity code:

         contract Test {
            uint a = 256;

            function set(uint s) {
                a = s;
            }

            function get() returns (uint) {
                return a;
            }
        }
        */
    String json = "{ " + "    'test1' : { " + "        'env' : { " + "            'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " + "            'currentDifficulty' : '0x0100', " + "            'currentGasLimit' : '0x0f4240', " + "            'currentNumber' : '0x00', " + "            'currentTimestamp' : '0x01', " + "            'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " + "        }, " + "        'logs' : [ " + "        ], " + "        'out' : '0x', " + "        'post' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a76586a0', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x0400' " + "                } " + "            }, " + "            '0000000000000000000000000000000001000008' : { " + "                'balance' : '0x67EB', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0DE0B6B3A7621175', " + "                'code' : '0x', " + "                'nonce' : '0x01', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " + "        'pre' : { " + "            '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                    '0x00' : '0x02' " + "                } " + "            }, " + "            'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " + "                'balance' : '0x0de0b6b3a7640000', " + "                'code' : '0x', " + "                'nonce' : '0x00', " + "                'storage' : { " + "                } " + "            } " + "        }, " + "        'transaction' : { " + "            'data' : '0x60fe47b10000000000000000000000000000000000000000000000000000000000000400', " + "            'gasLimit' : '0x061a80', " + "            'gasPrice' : '0x01', " + "            'nonce' : '0x00', " + "            'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " + "            'to' : '095e7baea6a6c7c4c2dfeb977efac326af552d87', " + "            'value' : '0x0186a0' " + "        } " + "    } " + "}";
    StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
    List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")) {

        @Override
        protected ProgramResult executeTransaction(Transaction tx) {
            // first emulating the constant call (Ethereum.callConstantFunction)
            // to ensure it doesn't affect the final state
            {
                Repository track = repository.startTracking();
                Transaction txConst = CallTransaction.createCallTransaction(0, 0, 100000000000000L, new RskAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), 0, CallTransaction.Function.fromSignature("get"), config.getNetworkConstants().getChainId());
                txConst.sign(new byte[] {});
                Block bestBlock = block;
                BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
                TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, new BlockStoreDummy(), null, blockFactory, invokeFactory, new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache()));
                TransactionExecutor executor = transactionExecutorFactory.newInstance(txConst, 0, bestBlock.getCoinbase(), track, bestBlock, 0).setLocalCall(true);
                executor.executeTransaction();
                track.rollback();
                System.out.println("Return value: " + new CallTransaction.IntType("uint").decode(executor.getResult().getHReturn()));
            }
            // now executing the JSON test transaction
            return super.executeTransaction(tx);
        }
    }.setstateTestUSeREMASC(true).runImpl();
    if (!res.isEmpty())
        throw new RuntimeException("Test failed: " + res);
}
Also used : BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) BlockStoreDummy(org.ethereum.db.BlockStoreDummy) MutableRepository(org.ethereum.db.MutableRepository) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) StateTestRunner(org.ethereum.jsontestsuite.runners.StateTestRunner) StateTestSuite(org.ethereum.jsontestsuite.StateTestSuite) RskAddress(co.rsk.core.RskAddress) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) Test(org.junit.Test)

Example 15 with TransactionExecutorFactory

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

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