use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class AionBlockchainImpl method generatePreBlock.
/**
* For generating the necessary transactions for a block
*
* @param block
* @return
*/
private RetValidPreBlock generatePreBlock(Block block) {
long saveTime = System.nanoTime();
List<AionTxReceipt> receipts = new ArrayList<>();
List<AionTxExecSummary> summaries = new ArrayList<>();
List<AionTransaction> transactions = new ArrayList<>();
if (!block.getTransactionsList().isEmpty()) {
boolean fork040Enable = forkUtility.is040ForkActive(block.getNumber());
if (fork040Enable) {
TransactionTypeRule.allowAVMContractTransaction();
}
try {
// Booleans moved out here so their meaning is explicit.
boolean isLocalCall = false;
boolean incrementSenderNonce = true;
boolean checkBlockEnergyLimit = true;
List<AionTxExecSummary> executionSummaries = BulkExecutor.executeAllTransactionsInBlock(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), block.getTransactionsList(), track, isLocalCall, incrementSenderNonce, fork040Enable, checkBlockEnergyLimit, LOGGER_VM, getPostExecutionWorkForGeneratePreBlock(repository), BlockCachingContext.PENDING, bestBlock.getNumber(), forkUtility.isUnityForkActive(block.getNumber()), forkUtility.isSignatureSwapForkActive(block.getNumber()));
for (AionTxExecSummary summary : executionSummaries) {
if (!summary.isRejected()) {
transactions.add(summary.getTransaction());
receipts.add(summary.getReceipt());
summaries.add(summary);
}
}
} catch (VmFatalException e) {
LOG.error("Shutdown due to a VM fatal error.", e);
System.exit(SystemExitCodes.FATAL_VM_ERROR);
}
}
Map<AionAddress, BigInteger> rewards = addReward(block);
return new RetValidPreBlock(transactions, rewards, receipts, summaries);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class StandaloneBlockchain method createBlockAndBlockTemplate.
/**
* create a testing mining block and the block template
*/
public MiningBlock createBlockAndBlockTemplate(Block parent, List<AionTransaction> txs, boolean waitUntilBlockTime, long currTimeSeconds) {
boolean unityForkEnabled = forkUtility.isUnityForkActive(parent.getNumber() + 1);
boolean signatureSwapForkEnabled = forkUtility.isSignatureSwapForkActive(parent.getNumber() + 1);
for (AionTransaction tx : txs) {
if (TXValidator.validateTx(tx, unityForkEnabled, signatureSwapForkEnabled).isFail()) {
throw new InvalidParameterException("invalid transaction input! " + tx.toString());
}
}
BlockContext context = createNewMiningBlockInternal(parent, txs, waitUntilBlockTime, currTimeSeconds);
if (context != null) {
MiningBlock block = context.block;
boolean newblock = miningBlockTemplate.put(ByteArrayWrapper.wrap(block.getHash()), block) == null;
return newblock ? block : null;
}
return null;
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingStateTest method invalidEnergyLimit.
@Test
public void invalidEnergyLimit() {
AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10L, energyPrice, TransactionTypes.DEFAULT, null);
assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.INVALID_TX_NRG_LIMIT);
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingStateTest method repayTransactionTest.
@Test
public void repayTransactionTest() {
AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), ByteUtils.fromHexString("1"), 21_000L * 10, energyPrice, TransactionTypes.DEFAULT, null);
AionTransaction repayTx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), ByteUtils.fromHexString("1"), 21_000L * 10, energyPrice * 2, TransactionTypes.DEFAULT, null);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx));
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(repayTx));
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(tx, pendingState.getPendingTransactions().get(0));
MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), Collections.emptyList(), false);
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(repayTx, pendingState.getPendingTransactions().get(0));
}
use of org.aion.base.AionTransaction in project aion by aionnetwork.
the class PendingStateTest method updateCacheTransactionsTest2.
@Test
public void updateCacheTransactionsTest2() {
List<AionTransaction> transactions = getMockTransaction(0, 2, 0);
List<AionTransaction> cachedTx = getMockTransaction(2, 2, 0);
assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(transactions.get(0)));
assertEquals(1, pendingState.getPendingTxSize());
pendingState.addTransactionsFromNetwork(cachedTx);
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(2, pendingState.getCachePoolSize());
transactions.add(cachedTx.get(0));
MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), transactions, false);
Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
assertEquals(1, pendingState.getPendingTxSize());
assertEquals(0, pendingState.getCachePoolSize());
assertEquals(cachedTx.get(1), pendingState.getPendingTransactions().get(0));
}
Aggregations