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;
}
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;
}
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;
}
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();
}
}
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();
}
Aggregations