Search in sources :

Example 1 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class ContractRunner method executeTransaction.

private TransactionExecutor executeTransaction(Transaction transaction) {
    Repository track = repository.startTracking();
    TransactionExecutor executor = new TransactionExecutor(new RskSystemProperties(), transaction, 0, RskAddress.nullAddress(), repository, blockStore, receiptStore, new ProgramInvokeFactoryImpl(), blockchain.getBestBlock());
    executor.init();
    executor.execute();
    executor.go();
    executor.finalization();
    track.commit();
    return executor;
}
Also used : RskSystemProperties(co.rsk.config.RskSystemProperties) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Example 2 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class CodeReplaceTest method executeTransaction.

public TransactionExecutor executeTransaction(BlockChainImpl blockchain, Transaction tx) {
    Repository track = blockchain.getRepository().startTracking();
    TransactionExecutor executor = new TransactionExecutor(config, tx, 0, RskAddress.nullAddress(), blockchain.getRepository(), blockchain.getBlockStore(), null, new ProgramInvokeFactoryImpl(), blockchain.getBestBlock());
    executor.init();
    executor.execute();
    executor.go();
    executor.finalization();
    track.commit();
    return executor;
}
Also used : Repository(org.ethereum.core.Repository) TransactionExecutor(org.ethereum.core.TransactionExecutor) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)

Example 3 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl in project rskj by rsksmart.

the class SyncProcessorTest method processBodyResponseWithTransactionAddsToBlockchain.

@Test
public void processBodyResponseWithTransactionAddsToBlockchain() {
    Account senderAccount = createAccount("sender");
    Account receiverAccount = createAccount("receiver");
    Map<RskAddress, AccountState> accounts = new HashMap<>();
    accounts.put(senderAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.valueOf(20000000)));
    accounts.put(receiverAccount.getAddress(), new AccountState(BigInteger.ZERO, Coin.ZERO));
    final NetBlockStore store = new NetBlockStore();
    BlockChainBuilder blockChainBuilder = new BlockChainBuilder();
    Blockchain blockchain = blockChainBuilder.ofSize(0, false, accounts);
    Block genesis = blockchain.getBestBlock();
    SimplePeer sender = new SimplePeer(new byte[] { 0x01 });
    Assert.assertEquals(0, blockchain.getBestBlock().getNumber());
    List<Transaction> txs = Collections.singletonList(createTransaction(senderAccount, receiverAccount, BigInteger.valueOf(1000000), BigInteger.ZERO));
    Block block = new BlockGenerator().createChildBlock(genesis, txs, blockChainBuilder.getRepository().getRoot());
    StateRootHandler stateRootHandler = new StateRootHandler(config.getActivationConfig(), new StateRootsStoreImpl(new HashMapDB()));
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams()), config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    BlockExecutor blockExecutor = new BlockExecutor(config.getActivationConfig(), new RepositoryLocator(blockChainBuilder.getTrieStore(), stateRootHandler), new TransactionExecutorFactory(config, blockChainBuilder.getBlockStore(), null, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), new BlockTxSignatureCache(new ReceivedTxSignatureCache())));
    Assert.assertEquals(1, block.getTransactionsList().size());
    blockExecutor.executeAndFillAll(block, genesis.getHeader());
    Assert.assertEquals(21000, block.getFeesPaidToMiner().asBigInteger().intValueExact());
    Assert.assertEquals(1, block.getTransactionsList().size());
    Assert.assertEquals(1, block.getNumber());
    Assert.assertArrayEquals(blockchain.getBestBlockHash(), block.getParentHash().getBytes());
    BlockNodeInformation nodeInformation = new BlockNodeInformation();
    TestSystemProperties config = new TestSystemProperties();
    BlockSyncService blockSyncService = new BlockSyncService(config, store, blockchain, nodeInformation, SyncConfiguration.IMMEDIATE_FOR_TESTING, DummyBlockValidator.VALID_RESULT_INSTANCE);
    SyncProcessor processor = new SyncProcessor(blockchain, mock(org.ethereum.db.BlockStore.class), mock(ConsensusValidationMainchainView.class), blockSyncService, SyncConfiguration.IMMEDIATE_FOR_TESTING, blockFactory, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new SyncBlockValidatorRule(new BlockUnclesHashValidationRule(), new BlockRootValidationRule(config.getActivationConfig())), DIFFICULTY_CALCULATOR, new PeersInformation(getChannelManager(), SyncConfiguration.IMMEDIATE_FOR_TESTING, blockchain, RskMockFactory.getPeerScoringManager()), mock(Genesis.class), mock(EthereumListener.class));
    List<Transaction> transactions = block.getTransactionsList();
    List<BlockHeader> uncles = block.getUncleList();
    long lastRequestId = new Random().nextLong();
    BodyResponseMessage response = new BodyResponseMessage(lastRequestId, transactions, uncles);
    processor.registerExpectedMessage(response);
    Deque<BlockHeader> headerStack = new ArrayDeque<>();
    headerStack.add(block.getHeader());
    List<Deque<BlockHeader>> headers = new ArrayList<>();
    headers.add(headerStack);
    List<BlockIdentifier> bids = new ArrayList<>();
    bids.add(new BlockIdentifier(blockchain.getBlockByNumber(0).getHash().getBytes(), 0));
    bids.add(new BlockIdentifier(block.getHash().getBytes(), 1));
    processor.startDownloadingBodies(headers, Collections.singletonMap(sender, bids), sender);
    ((DownloadingBodiesSyncState) processor.getSyncState()).expectBodyResponseFor(lastRequestId, sender.getPeerNodeID(), block.getHeader());
    processor.processBodyResponse(sender, response);
    Assert.assertEquals(1, blockchain.getBestBlock().getNumber());
    Assert.assertArrayEquals(block.getHash().getBytes(), blockchain.getBestBlockHash());
    Assert.assertTrue(processor.getExpectedResponses().isEmpty());
}
Also used : StateRootsStoreImpl(co.rsk.db.StateRootsStoreImpl) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) BlockStore(org.ethereum.db.BlockStore) HashMapDB(org.ethereum.datasource.HashMapDB) BlockChainBuilder(co.rsk.test.builders.BlockChainBuilder) SimplePeer(co.rsk.net.simples.SimplePeer) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) EthereumListener(org.ethereum.listener.EthereumListener) BlockGenerator(co.rsk.blockchain.utils.BlockGenerator) StateRootHandler(co.rsk.db.StateRootHandler) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) RepositoryLocator(co.rsk.db.RepositoryLocator) ConsensusValidationMainchainView(co.rsk.core.bc.ConsensusValidationMainchainView) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) BlockExecutor(co.rsk.core.bc.BlockExecutor) TestSystemProperties(co.rsk.config.TestSystemProperties) Test(org.junit.Test)

Example 4 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl 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 5 with ProgramInvokeFactoryImpl

use of org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl 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

ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)21 TransactionExecutorFactory (co.rsk.core.TransactionExecutorFactory)13 PrecompiledContracts (org.ethereum.vm.PrecompiledContracts)11 BlockExecutor (co.rsk.core.bc.BlockExecutor)9 HashMapDB (org.ethereum.datasource.HashMapDB)9 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)8 TestSystemProperties (co.rsk.config.TestSystemProperties)7 RepositoryLocator (co.rsk.db.RepositoryLocator)6 StateRootHandler (co.rsk.db.StateRootHandler)5 StateRootsStoreImpl (co.rsk.db.StateRootsStoreImpl)5 RepositoryBtcBlockStoreWithCache (co.rsk.peg.RepositoryBtcBlockStoreWithCache)5 RskAddress (co.rsk.core.RskAddress)4 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 DummyBlockValidator (co.rsk.validators.DummyBlockValidator)4 KeyValueDataSource (org.ethereum.datasource.KeyValueDataSource)4 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)3 TestCompositeEthereumListener (org.ethereum.listener.TestCompositeEthereumListener)3 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)2 RskSystemProperties (co.rsk.config.RskSystemProperties)2