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;
}
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;
}
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());
}
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);
}
}
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;
}
Aggregations