use of org.aion.base.db.ContractDetail in project aion by aionnetwork.
the class AionRepositoryCache method flushTo.
@Override
public void flushTo(Repository other, boolean clearStateAfterFlush) {
lock.lock();
try {
// determine which accounts should get stored
HashMap<AionAddress, AccountState> cleanedCacheAccounts = new HashMap<>();
for (Map.Entry<AionAddress, AccountState> entry : cachedAccounts.entrySet()) {
AccountState account = entry.getValue();
if (account != null && account.isDirty() && account.isEmpty()) {
// ignore contract state for empty accounts at storage
cachedDetails.remove(entry.getKey());
} else {
cleanedCacheAccounts.put(entry.getKey(), entry.getValue());
}
}
// determine which contracts should get stored
for (Map.Entry<AionAddress, ContractDetail> entry : cachedDetails.entrySet()) {
InnerContractDetails contractDetailsCache = (InnerContractDetails) entry.getValue();
contractDetailsCache.commit();
if (contractDetailsCache.origContract == null && other.hasContractDetails(entry.getKey())) {
// in forked block the contract account might not exist thus it is created without origin,
// but on the main chain details can contain data which should be merged into a single storage trie
// so both branches with different stateRoots are valid
contractDetailsCache.origContract = (ContractDetails) other.getContractDetails(entry.getKey());
contractDetailsCache.commit();
}
}
other.updateBatch(cleanedCacheAccounts, cachedDetails, cachedTransformedCode);
if (clearStateAfterFlush) {
cachedAccounts.clear();
cachedDetails.clear();
cachedTransformedCode.clear();
}
} finally {
lock.unlock();
}
}
Aggregations