use of org.aion.base.db.TransformedCodeInfoInterface in project aion by aionnetwork.
the class AionRepositoryImpl method updateBatch.
@Override
public void updateBatch(Map<AionAddress, AccountState> stateCache, Map<AionAddress, ContractDetail> detailsCache, Map<AionAddress, TransformedCodeInfoInterface> transformedCodeCache) {
rwLock.writeLock().lock();
try {
for (Map.Entry<AionAddress, AccountState> entry : stateCache.entrySet()) {
AionAddress address = entry.getKey();
AccountState accountState = entry.getValue();
ContractDetails contractDetails = (ContractDetails) detailsCache.get(address);
if (accountState.isDeleted()) {
// TODO-A: batch operations here
try {
worldState.delete(address.toByteArray());
} catch (Exception e) {
LOG.error("key deleted exception [{}]", e.toString());
}
if (LOG.isDebugEnabled()) {
LOG.debug("key deleted <key={}>", Hex.toHexString(address.toByteArray()));
}
} else {
if (!contractDetails.isDirty() || (contractDetails.getVmType() == InternalVmType.EITHER && !ContractInfo.isPrecompiledContract(address))) {
// ContractState class
if (accountState.isDirty()) {
updateAccountState(address, accountState);
if (LOG.isTraceEnabled()) {
LOG.trace("update: [{}],nonce: [{}] balance: [{}] [{}]", Hex.toHexString(address.toByteArray()), accountState.getNonce(), accountState.getBalance(), Hex.toHexString(contractDetails.getStorageHash()));
}
}
continue;
}
InnerContractDetails contractDetailsCache = (InnerContractDetails) contractDetails;
if (contractDetailsCache.origContract == null) {
contractDetailsCache.origContract = detailsDS.newContractDetails(address, contractDetailsCache.getVmType());
contractDetailsCache.commit();
}
StoredContractDetails parentDetails = (StoredContractDetails) contractDetailsCache.origContract;
// this method requires the encoding functionality therefore can be applied only to StoredContractDetails
detailsDS.update(address, parentDetails);
accountState.setStateRoot(parentDetails.getStorageHash());
updateAccountState(address, accountState);
cachedContractIndex.put(address, Pair.of(ByteArrayWrapper.wrap(accountState.getCodeHash()), parentDetails.getVmType()));
if (LOG.isTraceEnabled()) {
LOG.trace("update: [{}],nonce: [{}] balance: [{}] [{}]", Hex.toHexString(address.toByteArray()), accountState.getNonce(), accountState.getBalance(), Hex.toHexString(parentDetails.getStorageHash()));
}
}
}
for (Map.Entry<AionAddress, TransformedCodeInfoInterface> entry : transformedCodeCache.entrySet()) {
for (Map.Entry<ByteArrayWrapper, Map<Integer, byte[]>> infoMap : ((TransformedCodeInfo) entry.getValue()).transformedCodeMap.entrySet()) {
for (Map.Entry<Integer, byte[]> innerEntry : infoMap.getValue().entrySet()) {
setTransformedCode(entry.getKey(), infoMap.getKey().toBytes(), innerEntry.getKey(), innerEntry.getValue());
}
}
}
LOG.trace("updated: detailsCache.size: {}", detailsCache.size());
stateCache.clear();
detailsCache.clear();
transformedCodeCache.clear();
} finally {
rwLock.writeLock().unlock();
}
}
Aggregations