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