Search in sources :

Example 76 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class AionTxExecSummary method toString.

@Override
public String toString() {
    StringBuilder s = new StringBuilder();
    s.append(receipt.toString()).append("\n");
    s.append("value= ").append(value).append("\n");
    s.append("deletedAccounts [");
    if (!deletedAccounts.isEmpty()) {
        s.append("\n");
        for (AionAddress a : deletedAccounts) {
            s.append("  ").append(a).append("\n");
        }
    }
    s.append("]\n");
    return s.toString();
}
Also used : AionAddress(org.aion.types.AionAddress)

Example 77 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class AionTransaction method create.

/**
 * Factory method used by most of the kernel to create AionTransactions
 */
public static AionTransaction create(ECKey key, byte[] nonce, AionAddress destination, byte[] value, byte[] data, long energyLimit, long energyPrice, byte type, byte[] beaconHash) {
    byte[] timeStamp = ByteUtil.longToBytes(TimeInstant.now().toEpochMicro());
    byte[] transactionHashWithoutSignature = HashUtil.h256(TxUtil.rlpEncodeWithoutSignature(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, beaconHash));
    ISignature signature = key.sign(transactionHashWithoutSignature);
    byte[] rlpEncoding = TxUtil.rlpEncode(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, signature, beaconHash);
    byte[] transactionHash = HashUtil.h256(rlpEncoding);
    return new AionTransaction(nonce, new AionAddress(key.getAddress()), destination, value, data, energyLimit, energyPrice, type, timeStamp, transactionHashWithoutSignature, signature, rlpEncoding, transactionHash, beaconHash);
}
Also used : AionAddress(org.aion.types.AionAddress) ISignature(org.aion.crypto.ISignature)

Example 78 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class AionTransaction method createGivenTimestamp.

/**
 * Factory method used by some tests to create multiple transactions with the same timestamp
 */
public static AionTransaction createGivenTimestamp(ECKey key, byte[] nonce, AionAddress destination, byte[] value, byte[] data, long energyLimit, long energyPrice, byte type, byte[] timeStamp, byte[] beaconHash) {
    byte[] transactionHashWithoutSignature = HashUtil.h256(TxUtil.rlpEncodeWithoutSignature(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, beaconHash));
    ISignature signature = key.sign(transactionHashWithoutSignature);
    byte[] rlpEncoding = TxUtil.rlpEncode(nonce, destination, value, data, timeStamp, energyLimit, energyPrice, type, signature, beaconHash);
    byte[] transactionHash = HashUtil.h256(rlpEncoding);
    return new AionTransaction(nonce, new AionAddress(key.getAddress()), destination, value, data, energyLimit, energyPrice, type, timeStamp, transactionHashWithoutSignature, signature, rlpEncoding, transactionHash, beaconHash);
}
Also used : AionAddress(org.aion.types.AionAddress) ISignature(org.aion.crypto.ISignature)

Example 79 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class InvokableTxUtil method decode.

public static InternalTransaction decode(byte[] encodingWithVersion, AionAddress callingAddress, long energyPrice, long energyLimit) {
    // Right now we only have version 0, so if it is not 0, return null
    if (encodingWithVersion[0] != 0) {
        return null;
    }
    byte[] rlpEncoding = Arrays.copyOfRange(encodingWithVersion, 1, encodingWithVersion.length);
    try {
        SharedRLPList decodedTxList = RLP.decode2SharedList(rlpEncoding);
        RLPElement element = decodedTxList.get(0);
        if (!element.isList()) {
            throw new IllegalArgumentException("The rlp decode error, the decoded item should be a list");
        }
        SharedRLPList tx = (SharedRLPList) element;
        BigInteger nonce = new BigInteger(1, tx.get(RLP_META_TX_NONCE).getRLPData());
        BigInteger value = new BigInteger(1, tx.get(RLP_META_TX_VALUE).getRLPData());
        byte[] data = tx.get(RLP_META_TX_DATA).getRLPData();
        AionAddress destination;
        try {
            destination = new AionAddress(tx.get(RLP_META_TX_TO).getRLPData());
        } catch (Exception e) {
            destination = null;
        }
        AionAddress executor;
        try {
            executor = new AionAddress(tx.get(RLP_META_TX_EXECUTOR).getRLPData());
        } catch (Exception e) {
            executor = null;
        }
        if (executor != null && !executor.equals(AddressUtils.ZERO_ADDRESS) && !executor.equals(callingAddress)) {
            return null;
        }
        byte[] sigs = tx.get(RLP_META_TX_SIG).getRLPData();
        ISignature signature;
        AionAddress sender;
        if (sigs != null) {
            // Singature Factory will decode the signature based on the algo
            // presetted in main() entry.
            ISignature is = SignatureFac.fromBytes(sigs);
            if (is != null) {
                signature = is;
                sender = new AionAddress(is.getAddress());
            } else {
                return null;
            }
        } else {
            return null;
        }
        return createFromRlp(nonce, sender, destination, value, data, executor, energyLimit, energyPrice, signature, encodingWithVersion);
    } catch (Exception e) {
        LOG.error("Invokable tx -> unable to decode rlpEncoding. " + e);
        return null;
    }
}
Also used : AionAddress(org.aion.types.AionAddress) RLPElement(org.aion.rlp.RLPElement) BigInteger(java.math.BigInteger) SharedRLPList(org.aion.rlp.SharedRLPList) ISignature(org.aion.crypto.ISignature)

Example 80 with AionAddress

use of org.aion.types.AionAddress in project aion by aionnetwork.

the class AionBlockchainImpl method isValid.

public boolean isValid(BlockHeader header) {
    /*
         * The block header should already be validated at this point by P2P or mining,
         * but we are including the validation in case future import paths forget to add it.
         */
    if (!this.headerValidator.validate(header, LOG)) {
        return false;
    }
    Block[] threeGenParents = repository.getBlockStore().getThreeGenerationBlocksByHashWithInfo(header.getParentHash());
    Block parentBlock = threeGenParents[0];
    if (parentBlock == null) {
        return false;
    }
    Block grandparentBlock = threeGenParents[1];
    Block greatGrandparentBlock = threeGenParents[2];
    if (header.getSealType() == Seal.PROOF_OF_WORK) {
        if (forkUtility.isUnityForkActive(header.getNumber())) {
            if (grandparentBlock == null || greatGrandparentBlock == null) {
                return false;
            }
            return unityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, null) && unityGreatGrandParentBlockHeaderValidator.validate(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header, LOG);
        } else {
            return preUnityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, null) && preUnityGrandParentBlockHeaderValidator.validate(parentBlock.getHeader(), grandparentBlock == null ? null : grandparentBlock.getHeader(), header, LOG);
        }
    } else if (header.getSealType() == Seal.PROOF_OF_STAKE) {
        if (!forkUtility.isUnityForkActive(header.getNumber())) {
            LOG.warn("Trying to import a Staking block when the Unity fork is not active.");
            return false;
        }
        if (grandparentBlock == null) {
            LOG.warn("Staking block {} cannot find its grandparent", header.getNumber());
            return false;
        }
        if (forkUtility.isUnityForkBlock(parentBlock.getNumber())) {
            BigInteger expectedDiff = calculateFirstPoSDifficultyAtBlock(parentBlock);
            if (!expectedDiff.equals(header.getDifficultyBI())) {
                return false;
            }
            grandparentBlock = new GenesisStakingBlock(expectedDiff);
        } else if (forkUtility.isNonceForkBlock(parentBlock.getNumber())) {
            BigInteger expectedDiff = calculateFirstPoSDifficultyAtBlock(parentBlock);
            if (!expectedDiff.equals(header.getDifficultyBI())) {
                return false;
            }
        }
        BigInteger stake = null;
        try {
            stake = getStakingContractHelper().getEffectiveStake(new AionAddress(AddressSpecs.computeA0Address(((StakingBlockHeader) header).getSigningPublicKey())), ((StakingBlockHeader) header).getCoinbase(), parentBlock);
        } catch (Exception e) {
            LOG.error("Shutdown due to a fatal error encountered while getting the effective stake.", e);
            System.exit(SystemExitCodes.FATAL_VM_ERROR);
        }
        boolean result = unityParentBlockHeaderValidator.validate(header, parentBlock.getHeader(), LOG, stake);
        if (result) {
            if (forkUtility.isSignatureSwapForkActive(header.getNumber())) {
                result = vrfProofValidator.validate(parentBlock.getHeader(), grandparentBlock.getHeader(), header, LOG) && difficultyValidateAfterSeedNonceFork(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header);
            } else if (forkUtility.isNonceForkActive(header.getNumber())) {
                result = nonceSeedValidator.validate(grandparentBlock.getHeader(), parentBlock.getHeader(), header, LOG) && difficultyValidateAfterSeedNonceFork(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header);
            } else {
                result = unityGreatGrandParentBlockHeaderValidator.validate(grandparentBlock.getHeader(), greatGrandparentBlock.getHeader(), header, LOG);
            }
        }
        return result;
    } else {
        LOG.debug("Invalid header seal type!");
        return false;
    }
}
Also used : AionAddress(org.aion.types.AionAddress) GenesisStakingBlock(org.aion.zero.impl.types.GenesisStakingBlock) Block(org.aion.zero.impl.types.Block) BlockDetailsValidator.isValidBlock(org.aion.zero.impl.valid.BlockDetailsValidator.isValidBlock) GenesisStakingBlock(org.aion.zero.impl.types.GenesisStakingBlock) RetValidPreBlock(org.aion.zero.impl.types.RetValidPreBlock) MiningBlock(org.aion.zero.impl.types.MiningBlock) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) StakingBlock(org.aion.zero.impl.types.StakingBlock) BigInteger(java.math.BigInteger) VmFatalException(org.aion.zero.impl.vm.common.VmFatalException)

Aggregations

AionAddress (org.aion.types.AionAddress)491 Test (org.junit.Test)364 AionTransaction (org.aion.base.AionTransaction)275 BigInteger (java.math.BigInteger)194 ImportResult (org.aion.zero.impl.core.ImportResult)110 AionTxExecSummary (org.aion.base.AionTxExecSummary)97 RepositoryCache (org.aion.base.db.RepositoryCache)90 MiningBlock (org.aion.zero.impl.types.MiningBlock)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)80 ArrayList (java.util.ArrayList)76 ECKey (org.aion.crypto.ECKey)74 AionTxReceipt (org.aion.base.AionTxReceipt)60 Block (org.aion.zero.impl.types.Block)60 AccountState (org.aion.base.AccountState)56 HashMap (java.util.HashMap)42 DataWord (org.aion.util.types.DataWord)39 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)36 InternalTransaction (org.aion.types.InternalTransaction)32 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)29 BlockContext (org.aion.zero.impl.types.BlockContext)29