Search in sources :

Example 1 with InternalVmType

use of org.aion.base.InternalVmType in project aion by aionnetwork.

the class BulkExecutor method getInternalVmType.

/**
 * Returns the InternalVmType recorded for the given address.
 */
private static InternalVmType getInternalVmType(RepositoryCache repository, AionAddress destination) {
    // will load contract into memory otherwise leading to consensus issues
    RepositoryCache track = repository.startTracking();
    AccountState accountState = track.getAccountState(destination);
    InternalVmType vm;
    if (accountState == null) {
        // the address doesn't exist yet, so it can be used by either vm
        vm = InternalVmType.EITHER;
    } else {
        vm = repository.getVMUsed(destination, accountState.getCodeHash());
        // UNKNOWN is returned when there was no contract information stored
        if (vm == InternalVmType.UNKNOWN) {
            // use the in-memory value
            vm = track.getVmType(destination);
        }
    }
    return vm;
}
Also used : InternalVmType(org.aion.base.InternalVmType) RepositoryCache(org.aion.base.db.RepositoryCache) AccountState(org.aion.base.AccountState)

Example 2 with InternalVmType

use of org.aion.base.InternalVmType in project aion by aionnetwork.

the class ExternalStateForFvm method getVmType.

private InternalVmType getVmType(AionAddress destination) {
    // will load contract into memory otherwise leading to consensus issues
    RepositoryCache track = this.repository.startTracking();
    AccountState accountState = track.getAccountState(destination);
    InternalVmType vm;
    if (accountState == null) {
        // the address doesn't exist yet, so it can be used by either vm
        vm = InternalVmType.EITHER;
    } else {
        vm = this.repository.getVMUsed(destination, accountState.getCodeHash());
        // UNKNOWN is returned when there was no contract information stored
        if (vm == InternalVmType.UNKNOWN) {
            // use the in-memory value
            vm = track.getVmType(destination);
        }
    }
    return vm;
}
Also used : InternalVmType(org.aion.base.InternalVmType) RepositoryCache(org.aion.base.db.RepositoryCache) AccountState(org.aion.base.AccountState)

Example 3 with InternalVmType

use of org.aion.base.InternalVmType in project aion by aionnetwork.

the class ExternalStateForAvm method getVmType.

private InternalVmType getVmType(AionAddress destination) {
    // will load contract into memory otherwise leading to consensus issues
    RepositoryCache track = repositoryCache.startTracking();
    AccountState accountState = track.getAccountState(destination);
    InternalVmType vm;
    if (accountState == null) {
        // the address doesn't exist yet, so it can be used by either vm
        vm = InternalVmType.EITHER;
    } else {
        vm = repositoryCache.getVMUsed(destination, accountState.getCodeHash());
        // UNKNOWN is returned when there was no contract information stored
        if (vm == InternalVmType.UNKNOWN) {
            // use the in-memory value
            vm = track.getVmType(destination);
        }
    }
    return vm;
}
Also used : InternalVmType(org.aion.base.InternalVmType) RepositoryCache(org.aion.base.db.RepositoryCache) AccountState(org.aion.base.AccountState)

Example 4 with InternalVmType

use of org.aion.base.InternalVmType in project aion by aionnetwork.

the class AionRepositoryImpl method getContractDetails.

/**
 * @inheritDoc
 * @implNote Methods calling this can rely on the fact that the contract details returned is a
 *     newly created snapshot object. Since this method it locked, the methods using the
 *     returned object <b>do not need to be locked or synchronized</b>, depending on the
 *     specific use case.
 */
@Override
public StoredContractDetails getContractDetails(AionAddress address) {
    rwLock.readLock().lock();
    try {
        // That part is important cause if we have
        // to sync details storage according the trie root
        // saved in the account
        AccountState accountState = getAccountState(address);
        byte[] storageRoot = ConstantUtil.EMPTY_TRIE_HASH;
        byte[] codeHash = EMPTY_DATA_HASH;
        if (accountState != null) {
            storageRoot = accountState.getStateRoot();
            codeHash = accountState.getCodeHash();
        }
        InternalVmType vm = getVMUsed(address, codeHash);
        return detailsDS.getSnapshot(vm, address.toByteArray(), storageRoot);
    } finally {
        rwLock.readLock().unlock();
    }
}
Also used : InternalVmType(org.aion.base.InternalVmType) AccountState(org.aion.base.AccountState)

Example 5 with InternalVmType

use of org.aion.base.InternalVmType in project aion by aionnetwork.

the class AionRepositoryImpl method commitCachedVMs.

/**
 * Indexes the contract information.
 */
public void commitCachedVMs(ByteArrayWrapper inceptionBlock) {
    for (Map.Entry<AionAddress, Pair<ByteArrayWrapper, InternalVmType>> entry : cachedContractIndex.entrySet()) {
        AionAddress contract = entry.getKey();
        ByteArrayWrapper codeHash = entry.getValue().getLeft();
        InternalVmType vm = entry.getValue().getRight();
        // write only if not already stored
        ContractInformation ci = getIndexedContractInformation(contract);
        if (ci == null || !ci.getVmUsed(codeHash.toBytes()).isContract()) {
            saveIndexedContractInformation(contract, codeHash, inceptionBlock, vm, true);
        } else {
            if (ci != null && ci.getVmUsed(codeHash.toBytes()) != vm) {
                // possibly same code hash for AVM and FVM
                LOG.error("The stored VM type does not match the cached VM type for the contract {} with code hash {}.", contract, codeHash);
            }
        }
    }
    cachedContractIndex.clear();
}
Also used : InternalVmType(org.aion.base.InternalVmType) AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

InternalVmType (org.aion.base.InternalVmType)6 AccountState (org.aion.base.AccountState)5 RepositoryCache (org.aion.base.db.RepositoryCache)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AionAddress (org.aion.types.AionAddress)1 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)1 Pair (org.apache.commons.lang3.tuple.Pair)1