Search in sources :

Example 16 with TransactionExecutorFactory

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

the class RemascStorageProviderTest method paysOnlyBlocksWithEnoughBalanceAccumulatedAfterRFS.

@Test
public void paysOnlyBlocksWithEnoughBalanceAccumulatedAfterRFS() throws IOException {
    Constants constants = spy(Constants.testnet(null));
    // we need to pass chain id check, and make believe that testnet config has same chain id as cow account
    when(constants.getChainId()).thenReturn(Constants.REGTEST_CHAIN_ID);
    when(constants.getMinimumPayableGas()).thenReturn(BigInteger.valueOf(21000L));
    RskSystemProperties config = spy(new TestSystemProperties());
    when(config.getNetworkConstants()).thenReturn(constants);
    long txValue = 10000;
    long gasLimit = 100000L;
    long gasPrice = 10L;
    long lowGasPrice = 1L;
    long minerFee = 21000;
    RskAddress coinbase = randomAddress();
    BlockChainBuilder builder = new BlockChainBuilder().setTesting(true).setGenesis(genesisBlock).setConfig(config);
    RemascTestRunner testRunner = new RemascTestRunner(builder, this.genesisBlock).txValue(txValue).minerFee(minerFee).initialHeight(13).siblingElements(new ArrayList<>()).txSigningKey(this.cowKey).gasPrice(gasPrice);
    testRunner.setFixedCoinbase(coinbase);
    testRunner.start();
    Blockchain blockchain = testRunner.getBlockChain();
    RepositoryLocator repositoryLocator = builder.getRepositoryLocator();
    List<Block> blocks = new ArrayList<>();
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blockchain.getBestBlock(), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, gasPrice, 14, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, lowGasPrice, 15, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, gasPrice, 16, txValue, cowKey, null));
    blocks.add(RemascTestRunner.createBlock(genesisBlock, blocks.get(blocks.size() - 1), PegTestUtils.createHash3(), coinbase, Collections.emptyList(), gasLimit, lowGasPrice, 17, txValue, cowKey, null));
    blocks.addAll(createSimpleBlocks(blocks.get(blocks.size() - 1), 10, coinbase));
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), repositoryLocator, new TransactionExecutorFactory(config, builder.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
    for (Block b : blocks) {
        blockExecutor.executeAndFillAll(b, blockchain.getBestBlock().getHeader());
        Assert.assertEquals(ImportResult.IMPORTED_BEST, blockchain.tryToConnect(b));
        RepositorySnapshot repository = repositoryLocator.snapshotAt(blockchain.getBestBlock().getHeader());
        long blockNumber = blockchain.getBestBlock().getNumber();
        if (blockNumber == 24) {
            // before first special block
            assertEquals(Coin.valueOf(1663200L), RemascTestRunner.getAccountBalance(repository, coinbase));
        } else if (blockNumber == 25 || blockNumber == 26) {
            // after first and second special block
            assertEquals(Coin.valueOf(1829520L), RemascTestRunner.getAccountBalance(repository, coinbase));
        } else if (blockNumber == 27 || blockNumber == 28) {
            // after third and fourth special block
            assertEquals(Coin.valueOf(1999167L), RemascTestRunner.getAccountBalance(repository, coinbase));
        }
    }
}
Also used : BlockExecutor(co.rsk.core.bc.BlockExecutor) Constants(org.ethereum.config.Constants) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) RskAddress(co.rsk.core.RskAddress) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) RskSystemProperties(co.rsk.config.RskSystemProperties) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest)

Example 17 with TransactionExecutorFactory

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

the class WorldDslProcessor method processBlockChainCommand.

private void processBlockChainCommand(DslCommand cmd) {
    Block parent = world.getBlockByName(cmd.getArgument(0));
    int k = 1;
    while (cmd.getArgument(k) != null) {
        String name = cmd.getArgument(k);
        int difficulty = k;
        if (name != null) {
            StringTokenizer difficultyTokenizer = new StringTokenizer(name, ":");
            name = difficultyTokenizer.nextToken();
            difficulty = difficultyTokenizer.hasMoreTokens() ? parseDifficulty(difficultyTokenizer.nextToken(), k) : k;
        }
        Block block = blockBuilder.difficulty(difficulty).parent(parent).build();
        final ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
        final TestSystemProperties config = new TestSystemProperties();
        StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
        BlockExecutor executor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(world.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, world.getBlockStore(), null, new BlockFactory(config.getActivationConfig()), programInvokeFactory, null, world.getBlockTxSignatureCache()));
        executor.executeAndFill(block, parent.getHeader());
        world.saveBlock(name, block);
        parent = block;
        k++;
    }
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) BlockExecutor(co.rsk.core.bc.BlockExecutor) 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) StringTokenizer(java.util.StringTokenizer) TestSystemProperties(co.rsk.config.TestSystemProperties)

Example 18 with TransactionExecutorFactory

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

the class MinerHelper method processBlock.

public void processBlock(Block block, Block parent) {
    latestStateRootHash = null;
    totalGasUsed = 0;
    totalPaidFees = Coin.ZERO;
    txReceipts = new ArrayList<>();
    Repository track = repositoryLocator.startTrackingAt(parent.getHeader());
    // this variable is set before iterating transactions in case list is empty
    latestStateRootHash = track.getRoot();
    // RSK test, remove
    String stateHash1 = ByteUtil.toHexString(blockchain.getBestBlock().getStateRoot());
    String stateHash2 = ByteUtil.toHexString(repository.getRoot());
    if (stateHash1.compareTo(stateHash2) != 0) {
        logger.error("Strange state in block {} {}", block.getNumber(), block.getHash());
        panicProcessor.panic("minerserver", String.format("Strange state in block %d %s", block.getNumber(), block.getHash()));
    }
    int txindex = 0;
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockTxSignatureCache blockTxSignatureCache = new BlockTxSignatureCache(new ReceivedTxSignatureCache());
    for (Transaction tx : block.getTransactionsList()) {
        TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, null, null, blockFactory, null, new PrecompiledContracts(config, bridgeSupportFactory), blockTxSignatureCache);
        TransactionExecutor executor = transactionExecutorFactory.newInstance(tx, txindex++, block.getCoinbase(), track, block, totalGasUsed);
        executor.executeTransaction();
        long gasUsed = executor.getGasUsed();
        Coin paidFees = executor.getPaidFees();
        totalGasUsed += gasUsed;
        totalPaidFees = totalPaidFees.add(paidFees);
        track.commit();
        TransactionReceipt receipt = new TransactionReceipt();
        receipt.setGasUsed(gasUsed);
        receipt.setCumulativeGas(totalGasUsed);
        latestStateRootHash = track.getRoot();
        receipt.setPostTxState(latestStateRootHash);
        receipt.setTxStatus(executor.getReceipt().isSuccessful());
        receipt.setStatus(executor.getReceipt().getStatus());
        receipt.setTransaction(tx);
        receipt.setLogInfoList(executor.getVMLogs());
        txReceipts.add(receipt);
    }
}
Also used : TransactionExecutorFactory(co.rsk.core.TransactionExecutorFactory) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) Coin(co.rsk.core.Coin) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory)

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