use of org.aion.types.AionAddress in project aion by aionnetwork.
the class ContractExecutor method constructTransactionContext.
private static PrecompiledTransactionContext constructTransactionContext(IExternalCapabilitiesForPrecompiled capabilities, Transaction transaction, IExternalStateForPrecompiled externalState) {
AionAddress originAddress = transaction.senderAddress;
AionAddress callerAddress = transaction.senderAddress;
byte[] transactionHash = transaction.copyOfTransactionHash();
long blockNumber = externalState.getBlockNumber();
long energyRemaining = transaction.energyLimit - capabilities.calculateTransactionCost(transaction.copyOfTransactionData(), transaction.isCreate);
AionAddress destinationAddress = transaction.destinationAddress;
return new PrecompiledTransactionContext(destinationAddress, originAddress, callerAddress, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), transactionHash, transactionHash, blockNumber, energyRemaining, 0);
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTxInfo method fromRlp.
private static InternalTransaction fromRlp(SharedRLPList rlpInternalTx) {
Objects.requireNonNull(rlpInternalTx);
AionAddress from = new AionAddress(rlpInternalTx.get(INDEX_FROM).getRLPData());
AionAddress to;
boolean isCreate;
byte[] rlpTo = rlpInternalTx.get(INDEX_TO).getRLPData();
if (rlpTo == null || rlpTo.length == 0) {
to = null;
isCreate = true;
} else {
to = new AionAddress(rlpTo);
isCreate = false;
}
BigInteger nonce = new BigInteger(1, rlpInternalTx.get(INDEX_NONCE).getRLPData());
BigInteger value = new BigInteger(1, rlpInternalTx.get(INDEX_VALUE).getRLPData());
byte[] data = rlpInternalTx.get(INDEX_DATA).getRLPData();
long energyLimit = new BigInteger(1, rlpInternalTx.get(INDEX_LIMIT).getRLPData()).longValue();
long energyPrice = new BigInteger(1, rlpInternalTx.get(INDEX_PRICE).getRLPData()).longValue();
RejectedStatus status = // checking the length because zero (i.e. false) decodes to empty byte array
(rlpInternalTx.get(INDEX_STATUS).getRLPData().length == 1) ? RejectedStatus.REJECTED : RejectedStatus.NOT_REJECTED;
if (isCreate) {
return InternalTransaction.contractCreateTransaction(status, from, nonce, value, data, energyLimit, energyPrice);
} else {
return InternalTransaction.contractCallTransaction(status, from, to, nonce, value, data, energyLimit, energyPrice);
}
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class AionTxInfo method fromRlp.
private static InternalTransaction fromRlp(RLPList encoded) {
AionAddress from = new AionAddress(encoded.get(INDEX_FROM).getRLPData());
AionAddress to;
boolean isCreate;
byte[] rlpTo = encoded.get(INDEX_TO).getRLPData();
if (rlpTo == null || rlpTo.length == 0) {
to = null;
isCreate = true;
} else {
to = new AionAddress(rlpTo);
isCreate = false;
}
BigInteger nonce = new BigInteger(1, encoded.get(INDEX_NONCE).getRLPData());
BigInteger value = new BigInteger(1, encoded.get(INDEX_VALUE).getRLPData());
byte[] data = encoded.get(INDEX_DATA).getRLPData();
long energyLimit = new BigInteger(1, encoded.get(INDEX_LIMIT).getRLPData()).longValue();
long energyPrice = new BigInteger(1, encoded.get(INDEX_PRICE).getRLPData()).longValue();
RejectedStatus status = // checking the length because zero (i.e. false) decodes to empty byte array
(encoded.get(INDEX_STATUS).getRLPData().length == 1) ? RejectedStatus.REJECTED : RejectedStatus.NOT_REJECTED;
if (isCreate) {
return InternalTransaction.contractCreateTransaction(status, from, nonce, value, data, energyLimit, energyPrice);
} else {
return InternalTransaction.contractCallTransaction(status, from, to, nonce, value, data, energyLimit, energyPrice);
}
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class FvmTransactionExecutor method executeTransactions.
/**
* Executes the specified array of transactions using the FVM and returns a list of transaction
* summaries, such that the i'th summary pertains to the i'th transaction in the input.
*
* <p>If no post-execution work is specified then none will be run. Otherwise, the
* post-execution work will be applied in such a way that it appears, from the caller's
* perspective, as if it was run immediately after each transaction sequentially.
*
* @param repository The current snapshot of the kernel's repository layer.
* @param blockDifficulty The current best block's difficulty.
* @param blockNumber The current best block number.
* @param blockTimestamp The current best block timestamp.
* @param blockNrgLimit The current best block energy limit.
* @param blockCoinbase The address of the miner.
* @param transactions The transactions to execute.
* @param postExecutionWork The post-execute work, if any, to be run immediately after each
* transaction completes.
* @param logger A logger.
* @param decrementBlockEnergyLimit Whether to decrement the block energy limit (ie. if no
* decrement implication is block overflow won't be checked)
* @param allowNonceIncrement Whether to increment the sender nonce.
* @param isLocalCall Whether this is a local call or not.
* @param fork040enabled Whether or not the 0.4.0 fork is enabled.
* @param initialBlockEnergyLimit The initial block energy limit at the time of running these
* transactions.
* @return a list of transaction summaries pertaining to the transactions.
*/
public static List<AionTxExecSummary> executeTransactions(RepositoryCache repository, byte[] blockDifficulty, long blockNumber, long blockTimestamp, long blockNrgLimit, AionAddress blockCoinbase, AionTransaction[] transactions, PostExecutionWork postExecutionWork, Logger logger, boolean decrementBlockEnergyLimit, boolean allowNonceIncrement, boolean isLocalCall, boolean fork040enabled, long initialBlockEnergyLimit, boolean unityForkEnabled, boolean signatureSwapForkEnabled) throws VmFatalException {
List<AionTxExecSummary> transactionSummaries = new ArrayList<>();
long blockRemainingEnergy = initialBlockEnergyLimit;
// Run the transactions.
IExternalStateForFvm externalState = new ExternalStateForFvm(repository, blockCoinbase, getDifficultyAsDataWord(blockDifficulty), isLocalCall, allowNonceIncrement, fork040enabled, blockNumber, blockTimestamp, blockNrgLimit, unityForkEnabled, signatureSwapForkEnabled);
// Process the results of the transactions.
for (AionTransaction transaction : transactions) {
FvmWrappedTransactionResult wrappedResult = FastVirtualMachine.run(externalState, new ExternalCapabilitiesForFvm(), toAionTypesTransaction(transaction), fork040enabled);
TransactionResult result = wrappedResult.result;
List<AionAddress> deletedAddresses = wrappedResult.deletedAddresses;
if (result.transactionStatus.isFatal()) {
throw new VmFatalException(result.toString());
}
// Check the block energy limit & reject if necessary.
if (result.energyUsed > blockRemainingEnergy) {
TransactionStatus status = TransactionStatus.rejection("Invalid Energy Limit");
result = new TransactionResult(status, result.logs, result.internalTransactions, 0, ByteUtil.EMPTY_BYTE_ARRAY);
}
// Build the transaction summary.
AionTxExecSummary summary = buildTransactionSummary(transaction, result, deletedAddresses);
// If the transaction was not rejected, then commit the state changes.
if (!result.transactionStatus.isRejected()) {
externalState.commit();
}
// For non-rejected non-local transactions, make some final repository updates.
if (!isLocalCall && !summary.isRejected()) {
RepositoryCache repositoryTracker = repository.startTracking();
refundSender(repositoryTracker, summary, transaction, result);
payMiner(repositoryTracker, blockCoinbase, summary);
deleteAccountsMarkedForDeletion(repositoryTracker, summary.getDeletedAccounts(), result);
repositoryTracker.flushTo(repository, true);
}
// Do any post execution work.
if (postExecutionWork != null) {
postExecutionWork.doWork(repository, summary, transaction);
}
// Update the remaining block energy.
if (!result.transactionStatus.isRejected() && decrementBlockEnergyLimit) {
blockRemainingEnergy -= summary.getReceipt().getEnergyUsed();
}
if (logger.isDebugEnabled()) {
logger.debug("Transaction receipt: {}", summary.getReceipt());
logger.debug("Transaction logs: {}", summary.getLogs());
}
transactionSummaries.add(summary);
}
return transactionSummaries;
}
use of org.aion.types.AionAddress in project aion by aionnetwork.
the class StakingSeedCreationRule method validateInner.
public boolean validateInner(StakingBlockHeader stakingParent, MiningBlockHeader miningParent, StakingBlockHeader current, List<RuleError> errors) {
// retrieve components
byte[] parentSeed = stakingParent.getSeedOrProof();
byte[] signerAddress = new AionAddress(AddressSpecs.computeA0Address(current.getSigningPublicKey())).toByteArray();
byte[] powMineHash = miningParent.getMineHash();
byte[] powNonce = miningParent.getNonce();
int lastIndex = parentSeed.length + signerAddress.length + powMineHash.length + powNonce.length;
byte[] concatenated = new byte[lastIndex + 1];
System.arraycopy(parentSeed, 0, concatenated, 0, parentSeed.length);
System.arraycopy(signerAddress, 0, concatenated, parentSeed.length, signerAddress.length);
System.arraycopy(powMineHash, 0, concatenated, parentSeed.length + signerAddress.length, powMineHash.length);
System.arraycopy(powNonce, 0, concatenated, parentSeed.length + signerAddress.length + powMineHash.length, powNonce.length);
concatenated[lastIndex] = 0;
byte[] hash1 = h256(concatenated);
concatenated[lastIndex] = 1;
byte[] hash2 = h256(concatenated);
byte[] expectedSeed = new byte[hash1.length + hash2.length];
System.arraycopy(hash1, 0, expectedSeed, 0, hash1.length);
System.arraycopy(hash2, 0, expectedSeed, hash1.length, hash2.length);
byte[] newSeed = current.getSeedOrProof();
if (!Arrays.equals(expectedSeed, newSeed)) {
BlockHeaderValidatorUtil.addError(formatError(expectedSeed, newSeed), this.getClass(), errors);
return false;
} else {
return true;
}
}
Aggregations