Search in sources :

Example 11 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 12 with ProgramInvokeFactoryImpl

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

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

the class CallContractTest method callContract.

private static ProgramResult callContract(World world, RskAddress receiveAddress, byte[] data) {
    Transaction tx = CallTransaction.createRawTransaction(0, 0, 100000000000000L, receiveAddress, 0, data, config.getNetworkConstants().getChainId());
    tx.sign(new byte[] {});
    Block bestBlock = world.getBlockChain().getBestBlock();
    Repository repository = world.getRepositoryLocator().startTrackingAt(world.getBlockChain().getBestBlock().getHeader());
    BtcBlockStoreWithCache.Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache.Factory(config.getNetworkConstants().getBridgeConstants().getBtcParams());
    BridgeSupportFactory bridgeSupportFactory = new BridgeSupportFactory(btcBlockStoreFactory, config.getNetworkConstants().getBridgeConstants(), config.getActivationConfig());
    try {
        TransactionExecutorFactory transactionExecutorFactory = new TransactionExecutorFactory(config, null, null, blockFactory, new ProgramInvokeFactoryImpl(), new PrecompiledContracts(config, bridgeSupportFactory), world.getBlockTxSignatureCache());
        org.ethereum.core.TransactionExecutor executor = transactionExecutorFactory.newInstance(tx, 0, bestBlock.getCoinbase(), repository, bestBlock, 0).setLocalCall(true);
        executor.executeTransaction();
        return executor.getResult();
    } finally {
        repository.rollback();
    }
}
Also used : BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory) ProgramInvokeFactoryImpl(org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl) org.ethereum.core(org.ethereum.core) PrecompiledContracts(org.ethereum.vm.PrecompiledContracts) BtcBlockStoreWithCache(co.rsk.peg.BtcBlockStoreWithCache) RepositoryBtcBlockStoreWithCache(co.rsk.peg.RepositoryBtcBlockStoreWithCache) BridgeSupportFactory(co.rsk.peg.BridgeSupportFactory)

Example 14 with ProgramInvokeFactoryImpl

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

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

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