use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class AionPendingStateImpl method rerunTxsInPool.
private void rerunTxsInPool(Block block) {
addRepayTxToTxPool();
List<AionTransaction> pendingTxl = txPool.snapshotAll();
LOGGER_TX.info("rerunTxsInPool - snapshotAll tx[{}]", pendingTxl.size());
if (!pendingTxl.isEmpty()) {
for (AionTransaction tx : pendingTxl) {
LOGGER_TX.debug("rerunTxsInPool - loop: {}", tx);
AionTxExecSummary txSum = executeTx(tx);
AionTxReceipt receipt = txSum.getReceipt();
receipt.setTransaction(tx);
if (txSum.isRejected()) {
LOGGER_TX.debug("Invalid transaction in txPool: {}", tx);
txPool.remove(new PooledTransaction(tx, receipt.getEnergyUsed()));
removeBackupDBPendingTx(tx.getTransactionHash());
fireTxUpdate(receipt, PendingTransactionState.DROPPED, block);
} else {
if (repayTransaction.contains(tx)) {
txPool.updatePoolTransaction(new PooledTransaction(tx, receipt.getEnergyUsed()));
}
fireTxUpdate(receipt, PendingTransactionState.PENDING, block);
}
}
}
repayTransaction.clear();
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class TransactionCreateSpecificationTests method executeTransaction.
private AionTxExecSummary executeTransaction(AionTransaction transaction, boolean enableFork040) throws VmFatalException {
// Create a next block as context for the execution.
// Do not include the transaction in the block since it is expected to fail.
Block block = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList());
// TODO: refactor AionBlockchainImpl to contain a method for this call
List<AionTxExecSummary> list = BulkExecutor.executeAllTransactionsInBlock(block.getDifficulty(), block.getNumber() + 1, block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), List.of(transaction), this.blockchain.getRepository().startTracking(), false, true, enableFork040, true, LOGGER_VM, getPostExecutionWorkForGeneratePreBlock(blockchain.getRepository()), BlockCachingContext.PENDING, block.getNumber(), false, false);
return list.get(0);
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class TransactionCreateSpecificationTests method deployInternalAvmContractOnTopOfAddressWithStorageUsingAvmVersion2_DeployAndRequireSuccess.
@Test
public void deployInternalAvmContractOnTopOfAddressWithStorageUsingAvmVersion2_DeployAndRequireSuccess() throws VmFatalException {
// Deploy AVM contract.
AionTransaction deployTxAvm = BlockchainTestUtils.deployAvmContractTransaction(AvmContract.DEPLOY_INTERNAL, resourceProvider.factoryForVersion2, SENDER_KEY, BigInteger.ZERO);
AionAddress contract = TxUtil.calculateContractAddress(deployTxAvm);
Pair<Block, ImportResult> resultImport = BlockchainTestUtils.addMiningBlock(blockchain, blockchain.getBestBlock(), List.of(deployTxAvm));
assertThat(resultImport.getRight()).isEqualTo(ImportResult.IMPORTED_BEST);
// Call AVM contract to deploy new internal AVM contract (version with required success).
long internalLimit = 1_000_000;
AionTransaction deployInternal = BlockchainTestUtils.callSimpleAvmContractTransaction(resourceProvider.factoryForVersion2, SENDER_KEY, BigInteger.ONE, contract, "deployAndRequireSuccess", deployTxAvm.getData(), internalLimit);
AionAddress internalContract = new AionAddress(Hex.decode("a0268090998a99666b72cc452b9307438a34341047d9e0d7b92c9207bf413655"));
assertThat(blockchain.getRepository().hasAccountState(internalContract)).isFalse();
// Manipulate the repository to have a non-default storage value.
RepositoryCache cache = blockchain.getRepository().startTracking();
cache.addStorageRow(internalContract, ByteArrayWrapper.wrap(RandomUtils.nextBytes(16)), ByteArrayWrapper.wrap(RandomUtils.nextBytes(16)));
cache.saveVmType(internalContract, InternalVmType.AVM);
cache.flushTo(cache.getParent(), true);
// Check assumptions about contract state.
AccountState contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getStateRoot()).isNotEqualTo(EMPTY_TRIE_HASH);
assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
byte[] oldRoot = contractState.getStateRoot();
// Next, process the deploy transaction with fork040 enabled.
AionTxExecSummary result = executeTransaction(deployInternal, true);
assertThat(result.isFailed()).isTrue();
assertThat(result.getReceipt().getError()).isEqualTo("reverted");
assertThat(result.getNrgUsed()).isLessThan(BigInteger.valueOf(deployInternal.getEnergyLimit()));
assertThat(result.getLogs()).isEmpty();
InternalTransaction itx = result.getInternalTransactions().get(0);
assertThat(itx.isCreate).isTrue();
assertThat(TxUtil.calculateContractAddress(itx)).isEqualTo(internalContract);
assertThat(itx.isRejected).isTrue();
assertThat(itx.energyLimit).isEqualTo(internalLimit);
assertThat(result.getNrgUsed()).isGreaterThan(BigInteger.valueOf(itx.energyLimit));
contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
assertThat(contractState.getStateRoot()).isEqualTo(oldRoot);
assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class StakingContractHelper method callConstant.
private AionTxReceipt callConstant(AionTransaction tx, Block block) throws VmFatalException {
RepositoryCache repository = chain.getRepository().getSnapshotTo(block.getStateRoot()).startTracking();
List<AionTxExecSummary> summaries = AvmTransactionExecutor.executeTransactions(repository, block.getDifficultyBI(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), new AionTransaction[] { tx }, null, false, false, true, block.getNrgLimit(), BlockCachingContext.CALL.avmType, 0, chain.forkUtility.isUnityForkActive(block.getNumber()), chain.forkUtility.isSignatureSwapForkActive(block.getNumber()));
return summaries.get(0).getReceipt();
}
use of org.aion.base.AionTxExecSummary in project aion by aionnetwork.
the class InternalTransactionTest method testNestedCreate.
/*
pragma solidity ^0.4.0;
contract B {}
contract A {
address b;
function A() {
b = new B();
}
}
*/
@Test
public void testNestedCreate() throws Exception {
String contractA = "0x60506040523415600f5760006000fd5b5b60166048565b604051809103906000f0801582151615602f5760006000fd5b60006000508282909180600101839055555050505b6057565b604051605a8061009f83390190565b603a806100656000396000f30060506040526008565b60006000fd00a165627a7a72305820c0eea40d4778b01848164e58898e9e8c8ab068ed5ee36ed6f0582d119ecbbede002960506040523415600f5760006000fd5b6013565b603a8060206000396000f30060506040526008565b60006000fd00a165627a7a723058208c13bc92baf844f8574632dca44c49776516cb6cd537b10ed700bf61392b6ae80029";
StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
StandaloneBlockchain bc = bundle.bc;
ECKey deployerAccount = bundle.privateKeys.get(0);
// ======================
// DEPLOY
// ======================
BigInteger nonce = BigInteger.ZERO;
AionTransaction tx1 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx1), false);
AionTxExecSummary summary = executeTransaction(bc, context, tx1);
System.out.println(summary.getReceipt());
for (InternalTransaction tx : summary.getInternalTransactions()) {
System.out.println(tx);
}
}
Aggregations